Created
October 10, 2013 03:28
-
-
Save Qofar/6912600 to your computer and use it in GitHub Desktop.
[NicoCache_nl] 新検索βにキャッシュアイコンを表示する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name nicocacheicon for newsearchbeta | |
// @description 新検索βにキャッシュアイコンを表示する | |
// @include http://search.nicovideo.jp/* | |
// @version 1.0.0 | |
// ==/UserScript== | |
(function(){ | |
// nlMovieFetcher を導入している場合は[true]、導入していない場合は[false] | |
var IsMovieFetcher = true; | |
if(IsMovieFetcher){ | |
var sc = document.createElement("script"); | |
sc.type = "text/javascript"; | |
sc.src = "http://www.nicovideo.jp/local/nlMovieFetcher.js"; | |
document.body.appendChild(sc); | |
} | |
function set_nicochachicon(smidnode){ | |
var movielist = []; | |
for(key in smidnode){ | |
movielist.push(key); | |
} | |
if(!movielist.length) return; | |
GM_xmlhttpRequest({ | |
method: "GET", | |
url: "http://www.nicovideo.jp/cache/rsearch/"+movielist.join("|"), | |
onload: function(res){ | |
if(res.status === 200){ | |
var cachelist= JSON.parse(res.responseText); | |
for(var i=0, len=movielist.length; i<len; i++){ | |
var smid = movielist[i]; | |
var cache = cachelist[smid]; | |
var low = cachelist[smid + "low"]; | |
if(cache || low){ | |
var icon = "http://www.nicovideo.jp/local/cacheicon.gif"; | |
var color = "#C00000"; | |
// economy | |
if(low){ | |
icon = "http://www.nicovideo.jp/local/cacheeconomy.gif"; | |
color = "#C08000"; | |
} | |
var node = smidnode[smid]; | |
var img = document.createElement("img"); | |
img.src = icon; | |
img.style.position = "absolute"; | |
img.style.top = "85px"; | |
img.style.left = "0px"; | |
node.firstElementChild.appendChild(img); | |
var title = node.getElementsByClassName("title")[0].firstElementChild; | |
title.style.color = color; | |
} | |
} | |
} | |
} | |
}); | |
} | |
var observer = new MutationObserver(function(mutations){ | |
var smidnode = []; | |
mutations.forEach(function(mutation){ | |
if(mutation.addedNodes && mutation.addedNodes.length){ | |
var node = mutation.addedNodes[0]; | |
if(node.nodeType === Node.ELEMENT_NODE && | |
node.nodeName.toLowerCase() === "li" && | |
node.className.toLowerCase() === "video"){ | |
var smid = node.firstElementChild.firstElementChild.getAttribute("data-cmsid"); | |
// HashMap: smid = <li class="video"> | |
smidnode[smid] = node; | |
// fetch link | |
if(IsMovieFetcher){ | |
var fetch = document.createElement("a"); | |
fetch.href = "javascript:void(0);"; | |
fetch.setAttribute("onclick", "nicofetch(parentNode,'" + smid + "',3);"); | |
fetch.textContent = "fetch"; | |
var span = document.createElement("span"); | |
span.appendChild(fetch); | |
var count = node.getElementsByClassName("count")[0]; | |
count.appendChild(span); | |
} | |
} | |
} | |
}); | |
set_nicochachicon(smidnode); | |
}); | |
observer.observe(document.getElementById("row-results"), {childList: true , subtree: true}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment