Greasy Fork

Greasy Fork is available in English.

Progresigo

Add a count badge

当前为 2022-03-19 提交的版本,查看 最新版本

// ==UserScript==
// @name Progresigo
// @namespace http://random.com
// @description Add a count badge
// @include https://www.instagram.com/*/
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js
// @version 0.1.20220216
// @license MIT
// ==/UserScript==

var count = 0;
var array = [];
var totalCount = 0;
var mode = 2;
var perc = 0;

$( document ).ready(function() {
    //Badge display
    var txt = $("<div id='badgecount'></div>");
    $("body").append(txt);
    var badgetxt = $("<div id='badgetxt'>Scroll</div> <div id='badgeup'>⇱</div>");
    $("#badgecount").append(badgetxt);

    $("#badgecount").css("position", "fixed");
    $("#badgecount").css("bottom", 10);
    $("#badgecount").css("right", 10);
    $("#badgecount").css("color", "white");
    $("#badgecount").css("background-color", "#4d356a");
    $("#badgecount").css("padding", "7px");
    $("#badgecount").css("border-radius", "30px");
    $("#badgecount").css("font-weight", "bold");
    $("#badgecount").css("flex-direction", "row");
    $("#badgeup").css("padding-left", "5px");
    $("#badgeup").css("font-size", "20px");

    // IMG count shown for IG
    count = $("img[decoding='auto']").length;

    $( "#badgetxt" ).click(function() {
        if (mode == 1) {
            mode = 2;
            $("#badgetxt").text(perc + "%");
        } else {
            mode = 1;
            $("#badgetxt").text(count + "/" + totalCount);
        }
    });

    $( "#badgeup" ).click(function() {
        $( "html" ).scrollTop( 0 );
    });

});

$( window ).scroll(function() {
    //IG total count
    totalCount = $("div:contains('publications'):eq(2)").children().text().replace(/\s/g, '');

    $("img[decoding='auto']").each(function( index ) {
        if (array.indexOf($( this ).attr('src')) === -1) {
            array.push($( this ).attr('src'));
        }
    });

    count = array.length;

    if (count > totalCount) {
        count = totalCount;
    }

    perc = Math.round((count * 100) / totalCount);
    if (mode == 1) {
        $("#badgetxt").text(count + "/" + totalCount);
    }
    if (mode == 2) {
        $("#badgetxt").text(perc + "%");
    }

});