Skip to content

Instantly share code, notes, and snippets.

@azu
Created January 8, 2009 08:37
Show Gist options
  • Save azu/44644 to your computer and use it in GitHub Desktop.
Save azu/44644 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name NicoVideo_mark
// @namespace d.hatena.ne.jp/Sore_0
// @original d.hatena.ne.jp/shrkw
// @description Mark your favorite videos to watch after
// @include http://www.nicovideo.jp/*
// @include http://ch.nicovideo.jp/video/*
// @exclude http://www.nicovideo.jp/thumb*
// @update 2008/12/07
// @version 0.3.3
// @require http://kojim71.googlepages.com/update_checker.user.js
// ==/UserScript==
(function(){
// location page
var what_pg = "";
if(/http:\/\/.*?\.nicovideo\.jp\/([^\/]*)\/?/.test(location.href))what_pg = RegExp.$1;
if(what_pg == "watch")return;
// class of clickable space
var coc = "";
function main(context) {
var $clickable = [];
var $clickable_search = [];
if(context && what_pg == "ranking"){
for(var i=0;i<context.length;i++){
$clickable.push($x("descendant::a[contains(concat(' ',normalize-space(@class),' '), ' video ')][contains(@href, 'watch')]/../..[not(contains(@class, 'mb16p4'))]/..", context[i])[0]);
$clickable_search.push($x("descendant::div[contains(concat(' ',normalize-space(@class),' '), ' thumb_frm ')]", context[i])[0]);
}
} else {
var context = (context) ? context[0] : document;
$clickable = $x("descendant::a[contains(concat(' ',normalize-space(@class),' '), ' video ')][contains(@href, 'watch')]/../..[not(contains(@class, 'mb16p4'))]/..", context);
$clickable_search = $x("descendant::div[contains(concat(' ',normalize-space(@class),' '), ' thumb_frm ')]", context);
}
switch (what_pg){
case "watch": return;
case "ranking":
coc = "thumb_frm";
$clickable = $clickable_search;break;
case "static":
$clickable = $x("descendant::a[contains(concat(' ',normalize-space(@class),' '), ' video ')]/../../../..", context); break;
case "tag":
coc = "thumb_frm";
$clickable = $clickable_search; break;
case "search":
coc = "thumb_frm";
$clickable = $clickable_search; break;
case "newarrival":
coc = "thumb_frm";
$clickable = $clickable_search; break;
case "recent":
coc = "thumb_frm";
$clickable = $clickable_search; break;
case "myvideo":
coc = "thumb_frm";
$clickable = $clickable_search; break;
case "hotlist":
coc = "thumb_frm";
$clickable = $clickable_search; break;
case "user":
var $clickable = $x("descendant::a[contains(concat(' ',normalize-space(@class),' '), ' video ')][contains(@href, 'watch')]/../..", context); break;
case "mymemory":
$clickable = $clickable.map(parent); break;
case "history":
$clickable = $clickable.map(parent); break;
case "mylist":
var $clickable = $x("id('mylists')//descendant::a[contains(concat(' ',normalize-space(@class),' '), ' video ')][contains(@href, 'watch')]/../..[not(contains(@class, 'mb16p4'))]/..", context); break;
case "my": break;
case "mylist_edit": break;
// channel & community video page
case "video": break;
// toppage
default :
coc = "thumb_frm";
$clickable = $clickable_search; break;
}
$clickable.forEach(click);
}
function parent(elem){return elem.parentNode;}
function click(elem){
var self = elem;
elem.addEventListener("click", function(e){
if(e.target.tagName == "A" || e.target.tagName == "INPUT")return;
if(e.target.tagName == "IMG")e.preventDefault();
toggleClass(self)}, false);
}
function toggleClass(elem){
if(coc == "thumb_frm"){
elem.setAttribute("class", (elem.className == "thumb_frm") ? "marked" : "thumb_frm");
elem.style.border = "2px solid #CCCCCC";
elem.style.padding = "6px";
}else{
elem.setAttribute("class", (elem.className == "marked") ? "" : "marked");
}
}
function $x(xpath, context){
var x = document.evaluate(xpath, context, null, 7, null);
var array = [];
for(var i = 0;i < x.snapshotLength;i++){
array.push(x.snapshotItem(i));
}
return array;
}
function addFilter(filter, i) {
i = i || 4
if (window.AutoPagerize && window.AutoPagerize.addFilter) {
window.AutoPagerize.addFilter(filter);
}
else if (i > 1) {
setTimeout(arguments.callee, 1000, filter, i - 1);
}
}
main();
addFilter(main);
GM_addStyle(".marked {" +
"background:#FFCCCC none repeat scroll 0 0;" +
"}");
new UpdateChecker({
script_name: "NicoVideo_mark"
,script_url: "http://kojim71.googlepages.com/nicomark.user.js"
,current_version: "0.3.3"
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment