Show48 Local Watched Indicator

Add Watched indicator to show48.com

目前為 2015-05-27 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Show48 Local Watched Indicator
// @namespace    http://sk3dsu-phantasy.com/
// @version      0.2.1
// @description  Add Watched indicator to show48.com
// @author       sk3dsu (Fadli)
// @match        *://*.show48.com/*
// @require      http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js
// @grant        GM_getValue 
// @grant        GM_setValue
// @grant        GM_deleteValue
// ==/UserScript==

function GM_main ($) {
    var urlPath  = window.location.pathname;

    console.log(urlPath);

    if( $('#video-toolbar').length )
    {
        console.log("video-toolbar exist");

        urlPath = urlPath.slice(1);
        urlPath = urlPath.slice(0, -1);

        console.log(urlPath);
        
        var theValue = GM_getValue(urlPath, 0);
        
        console.log('theValue: ' + theValue);
        
        if ($(".video-toolbar-item-like-bar")[0])
        {
            var newDiv = document.createElement("div"); 
            newDiv.className = "like-dislike pull-left";
            
            var span = document.createElement("span");
            span.id = "pawWatch";
            span.innerHTML = "<i class='fa fa-paw'></i> Watched";
            
            if (theValue == 1)
            {
                span.style.color = "green";
            }
            
            var input = document.createElement("input");
            input.id = "isWatched";
            input.value = theValue;
            input.type = "hidden";
            
            newDiv.appendChild(span);
            
            var parentDiv = document.getElementsByClassName("video-toolbar-item-like-bar")[0]; 
            var currentDiv = parentDiv.children[0];
            currentDiv.appendChild (newDiv); 
            
            newDiv.addEventListener("click", function(){
                if (input.value == 1)
                {
                    input.value = 0;
                    span.style.color = "";
                    GM_deleteValue(urlPath);
                }
                else 
                {
                    input.value = 1;
                    span.style.color = "green";
                    GM_setValue(urlPath, 1);
                }
                
            });
           
        }
    }
    else
    {
        console.log("video-toolbar NOT exist");

        var smartBoxes = document.getElementsByClassName("smart-box"); 
        
        console.log("smartbox: " + smartBoxes.length);
        
        if (smartBoxes.length > 0) 
        {
            var firstSmartBox = smartBoxes[0];
            
            console.log("smartbox id: " + firstSmartBox.id);
        
            // get the second child, not the header child
            var latestVideoDiv = firstSmartBox.childNodes[1];

            var videoItems = latestVideoDiv.getElementsByClassName("video-item");
            
            for (i = 0; i < videoItems.length; i++)
            {
            
                var videoItem = videoItems[i];

                var itemThumbnail = videoItem.firstChild.nextSibling;
                var itemHref = itemThumbnail.childNodes[1];

                var withoutProtocol = itemHref.href.slice(7);
                var urlExplode = withoutProtocol.split("/");
                var urlPath = urlExplode[1];

                console.log(urlPath);

                var theValue = GM_getValue(urlPath, 0);

                console.log('theValue: ' + theValue);

                if (theValue == 1)
                {
                    var itemOverlay = itemHref.childNodes[1];

                    var span = document.createElement("span");
                    span.id = "pawWatch";
                    span.className = "fa fa-paw";
                    span.style.color = "green";
                    span.style.fontSize = "200%";
                    span.style.opacity = "0.6";

                    itemOverlay.appendChild(span);
                }
            }
            
        }
        
    }
}

if (typeof jQuery === "function") {
    console.log ("Running with local copy of jQuery!");
    GM_main (jQuery);
}
else {
    console.log ("fetching jQuery from some 3rd-party server.");
    add_jQuery (GM_main, "1.11.2");
}

function add_jQuery (callbackFn, jqVersion) {
    var jqVersion   = jqVersion || "1.11.2";
    var D           = document;
    var targ        = D.getElementsByTagName ('head')[0] || D.body || D.documentElement;
    var scriptNode  = D.createElement ('script');
    scriptNode.src  = 'http://ajax.googleapis.com/ajax/libs/jquery/'
                    + jqVersion
                    + '/jquery.min.js'
                    ;
    scriptNode.addEventListener ("load", function () {
        var scriptNode          = D.createElement ("script");
        scriptNode.textContent  =
            'var gm_jQuery  = jQuery.noConflict (true);\n'
            + '(' + callbackFn.toString () + ')(gm_jQuery);'
        ;
        targ.appendChild (scriptNode);
    }, false);
    targ.appendChild (scriptNode);
}

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址