Created
February 2, 2009 21:19
-
-
Save azu/57101 to your computer and use it in GitHub Desktop.
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 NicoVideo Multiple Tag Search Tool | |
// @namespace http://endflow.net/ | |
// @description allows to search with multiple tags from tag list in NicoVideo watching page. | |
// @include http://*.nicovideo.jp/watch/* | |
// @version 0.1.2 | |
// ==/UserScript== | |
// @author Yuki KODAMA (Twitter: kuy, Skype: netkuy) | |
// @history [2009-02-02] 0.1.0 first version | |
// [2009-02-02] 0.1.1 bugfix: apply ui changes after finished editing | |
// [2009-02-02] 0.1.2 Hyakka button fix & serch as word | |
(function(){ | |
var w = this.unsafeWindow || window; | |
// main | |
init(); | |
// functions | |
function init(){ | |
insertCheckbox(); | |
insertSearchButton(); | |
insertTagSearchButton(); | |
$x('id("video_tags")/p//a[contains(@href,"javascript:")]').forEach(function(edit){ | |
edit.addEventListener('click', function(){hookFButton()}, false); | |
}); | |
} | |
function insertCheckbox(){ | |
$if($x('id("video_tags")//a[@rel="tag"]'), function(tag){ | |
var span = $n('span'); | |
span.innerHTML = '<input type="checkbox" value="' + tag.innerHTML | |
+ '"onclick="nvmts_onclick();" />'; | |
tag.parentNode.insertBefore(span, tag); | |
}, function(){ | |
setTimeout(insertCheckbox, 300); | |
}); | |
} | |
function insertTagSearchButton(){ | |
if($('nvmtst')) return; | |
$x('id("video_tags")/p[@class="tag_txt"]/strong[1]')[0].innerHTML | |
+= '<nobr> <a style="color: rgb(0,51,255);" href="javascript:void(0);" id="nvmtst">【タグ検索】</a></nobr>'; | |
} | |
function insertSearchButton(){ | |
if($('nvmtsw')) return; | |
$x('id("video_tags")/p[@class="tag_txt"]/strong[1]')[0].innerHTML | |
+= '<nobr> <a style="color: rgb(0,51,255);" href="javascript:void(0);" id="nvmtsw">【検索】</a></nobr>'; | |
} | |
function hookFButton(){ | |
$IF($x('id("tag_edit_form")//form[contains(@action,"javascript:")]/input'), function(finish){ | |
finish.addEventListener('click', function(){ | |
setTimeout(function(){init()}, 300); | |
}, false); | |
}, function(){ | |
setTimeout(hookFButton, 100); | |
}); | |
} | |
w.nvmts_onclick = function(){ | |
var button = $('nvmtst'); | |
button.href = 'http://www.nicovideo.jp/tag/' | |
+ $x('id("video_tags")//input[@type="checkbox"]') | |
.filter(function(cb){return cb.checked}) | |
.map(function(cb){return cb.value}) | |
.join('+'); | |
var button = $('nvmtsw'); | |
button.href = 'http://www.nicovideo.jp/search/' | |
+ $x('id("video_tags")//input[@type="checkbox"]') | |
.filter(function(cb){return cb.checked}) | |
.map(function(cb){return cb.value}) | |
.join('+'); | |
} | |
// utils | |
function $if(a,t,f,o){(a!=null&&0<a.length)?a.forEach(function(i){t.call(o,i)}):f.call(o)} | |
function $IF(a,t,f,o){(a!=null&&0<a.length)?t.call(o,a[0]):f.call(o)} | |
function $x(x,c){c=c||w.document;var r=w.document.evaluate(x,c,null,4,null); | |
for(var i,nodes=[];i=r.iterateNext();nodes.push(i));return nodes} | |
function $(id){return w.document.getElementById(id)} | |
function $n(tagName){return w.document.createElement(tagName)} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment