Created
February 23, 2009 04:22
-
-
Save azu/68786 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 Add Mylist Link | |
// @author favril | |
// @namespace http://script41self.seesaa.net/ | |
// @description ニコニコ動画のメニューバーに、mylistへのリンクを追加するスクリプト | |
// @version 0.1.2 | |
// @include http://www.nicovideo.jp/* | |
// @require http://favril.myspace.googlepages.com/noriaki_updatechecker_uc-20080823.js | |
// ==/UserScript== | |
(function(){ | |
var list = eval("("+GM_getValue("mylist_list")+")") || {}; | |
// mylistをげっとする | |
function insertmenu(list){ | |
var slct = document.createElement("select"); | |
slct.setAttribute("class", "TXT12"); | |
slct.style.width = "80px"; | |
slct.setAttribute("onChange", "AML_link();"); | |
slct.id = "AML_slct"; | |
var opt = document.createElement("option"); | |
opt.value = ""; | |
opt.innerHTML = "--myslit--"; | |
slct.appendChild(opt); | |
for(var i=0; i<list.length; i++){ | |
// groups.add(***) : *** だけにして、さらに , で分割する | |
var sp = list[i].substring(11, list[i].length-1).split(", "); | |
opt = document.createElement("option"); | |
opt.value = sp[0]; | |
opt.innerHTML = sp[1].substring(1, sp[1].length-1) + " (" + sp[4] + ")"; | |
slct.appendChild(opt); | |
} | |
var refresh = document.createElement("span"); | |
refresh.innerHTML = "更新"; | |
refresh.setAttribute("style","cursor:default"); | |
refresh.addEventListener("click", getmylists, false); | |
// 挿入位置探し | |
var inpos = document.getElementById("recent_log"); | |
// 挿入 | |
inpos.parentNode.insertBefore(slct, inpos); | |
inpos.parentNode.insertBefore(refresh, inpos); | |
inpos.parentNode.insertBefore(document.createTextNode(" | "), inpos); | |
// onchange用の関数を仕込む | |
var script = document.createElement("script"); | |
script.setAttribute("type", "text/javascript"); | |
script.innerHTML = "function AML_link(){var slct = document.getElementById('AML_slct');var idx = slct.selectedIndex;if(idx != 0) {location.href = '/mylist/' + slct.options[idx].value;}}"; | |
document.getElementsByTagName("head")[0].appendChild(script); | |
} | |
function getmylists(){ | |
GM_xmlhttpRequest({ | |
method: "get", | |
url: "http://www.nicovideo.jp/mylistgroup_edit", | |
headers: { "User-Agent": "Mozilla/5.0 Greasemonkey (Add Mylist Linker)" }, | |
onload: function(res){ | |
var list = res.responseText.match(/groups\.add\([^\)]+\)/g); | |
//GM_log(list); | |
if(!list) return; // mylistなし | |
GM_setValue("mylist_list", list.toSource()); | |
//insertmenu(list); | |
}, | |
onerror: function(res){ GM_log(res.status + ":" + res.statusText); } | |
}); | |
} | |
if(list) | |
insertmenu(list); | |
else | |
getmylists(); | |
// update lib | |
// http://blog.fulltext-search.biz/archives/2008/08/update-checker-4-greasemonkey.html | |
new UpdateChecker({ | |
script_name: "Add Mylist Link", | |
script_url: "http://script41self.up.seesaa.net/user_js/add_mylist_link.user.js", | |
current_version: "0.1.2", | |
more_info_url: "http://script41self.seesaa.net/article/106627828.html" | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment