Show48 Local Watched Indicator

Add Watched indicator to show48.com

Od 29.05.2015.. Pogledajte najnovija verzija.

// ==UserScript==
// @name         Show48 Local Watched Indicator
// @namespace    http://sk3dsu-phantasy.com/
// @version      0.3.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 ($) {
    
    // Video Page itself
    if( $('#video-toolbar').length )
    {        
        if ($(".video-toolbar-item-like-bar")[0])
        {
            var urlPath  = window.location.pathname;
            urlPath = urlPath.slice(1);
            urlPath = urlPath.slice(0, -1);
            
            var theValue = GM_getValue(urlPath, 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)
            {
                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
    {

        var smartBoxes = document.getElementsByClassName("smart-box"); 
        
        // Landing Page Latest Video Area
        if (smartBoxes.length) 
        {
            var firstSmartBox = smartBoxes[0];
        
            // 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 urlPath = getUrlPath(itemHref);
                var theValue = GM_getValue(urlPath, 0);

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

                    var span = createPawWatchSpanElement();

                    itemOverlay.appendChild(span);
                }
            }
            
        }
        else 
        {
            // Any Page with video-listing and thumbnail e.g. show, drama
            var videoListing = document.getElementsByClassName("video-listing"); 
            
            if (videoListing.length)
            {   
                var itemThumbnails = document.getElementsByClassName("item-thumbnail"); 
                
                for (i = 0; i < itemThumbnails.length; i++)
                {
                    var itemHref = itemThumbnails[i].childNodes[1];               
                    var urlPath = getUrlPath(itemHref);
                    var theValue = GM_getValue(urlPath, 0);

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

                        var span = createPawWatchSpanElement();

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

function createPawWatchSpanElement() {
    
    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";
    
    return span;
}

function getUrlPath(itemHref) {
    var withoutProtocol = itemHref.href.slice(7);
    var urlExplode = withoutProtocol.split("/");
    var urlPath = urlExplode[1];
    
    return urlPath;
}

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);
}