Skip to content

Instantly share code, notes, and snippets.

@awq
Created September 23, 2010 06:09
Show Gist options
  • Save awq/593209 to your computer and use it in GitHub Desktop.
Save awq/593209 to your computer and use it in GitHub Desktop.
Add AutoPager function to new version NicoNicoLive
// ==UserScript==
// @name ap suppl NicoNicoLive
// @namespace http://d.hatena.ne.jp/awq/
// @include http://live.nicovideo.jp/recent*
// @description Add AutoPager function to new version NicoNicoLive
// ==/UserScript==
/*****
-Requirement
This script requires pre-installed autopagerize.user.js by swdyh (http://autopagerize.net/).
*****/
//check new version
if(document.evaluate('id("cg")/a[@class="change_old"]', document, null, 3, null).booleanValue) return;
var changeDoc = function (doc)
{
//modify nextlink
var nextLink = doc.evaluate('id("Left_box")/div[@class="programPager"]/a[@href]', doc, null, 7, null);
for(var i = 0, l = nextLink.snapshotLength; i < l; i++)
{
var params = nextLink.snapshotItem(i).getAttribute('onclick').match("'([^']+)', '([^']+)', '([^']+)', (\\d+)");
nextLink.snapshotItem(i).href = "recent2onairstreams?sort=" + params[2] + "&tab=" + params[1] + "&p=" + params[4] + "&tags=" + doc.getElementById(params[3]).innerHTML;
}
//modify tag
var ct = document.evaluate('//a[starts-with(@onclick,"return ct(this,")]', document, null, 7, null);
for(var i = 0, l = ct.snapshotLength; i < l; i++)
{
var sort = ct.snapshotItem(i).getAttribute('onclick').match("'([^']+)'")? RegExp.$1: '';
var tab = location.href.match('[&?]tab=([^&]+)')[1];
var tag = ct.snapshotItem(i).innerHTML.match('^[^(]+')[0];
ct.snapshotItem(i).href = "recent2onairstreams?sort=" + sort + "&tab=" + tab + "&tags=" + tag;
ct.snapshotItem(i).removeAttribute('onclick');
}
//modify sorter
doc.getElementById('selectsort').removeAttribute('onchange');
doc.getElementById('selectsort').addEventListener('change', function()
{
var sort = doc.getElementById('selectsort').value;
var tab = location.href.match('[&?]tab=([^&]+)')[1];
location.href = '/recent2onairstreams?sort=' + this.value + '&tab=' + tab;
}, false);
//stylesheet
if(!document.evaluate('//link[@rel="stylesheet"]', document, null, 3, null).booleanValue)
{
var base2css = document.createElement('link');
base2css.href = 'inc/base2.css';
base2css.charset = 'utf-8';
base2css.type = 'text/css';
base2css.rel = 'stylesheet';
document.getElementsByTagName("head")[0].appendChild(base2css);
var reset2css = document.createElement('link');
reset2css.href = 'inc/reset2.css';
reset2css.charset = 'utf-8';
reset2css.type = 'text/css';
reset2css.rel = 'stylesheet';
document.getElementsByTagName("head")[0].appendChild(reset2css);
var recent2css = document.createElement('link');
recent2css.href = 'inc/recent2.css';
recent2css.charset = 'utf-8';
recent2css.type = 'text/css';
recent2css.rel = 'stylesheet';
document.getElementsByTagName("head")[0].appendChild(recent2css);
document.body.setAttribute('style', "background-color:#fff;");
}
};
var SITEINFO = [];
SITEINFO.push(
{
"name": 'ニコニコ生放送(新バージョン)',
"data":
{
"url": '^http://live\.nicovideo\.jp/',
"nextLink": '(id("Left_box")/div[@class="programPager"]/a)[last()][not(contains(@class,"active"))]',
"pageElement": 'id("Left_box")/div',
"exampleUrl": 'http://live.nicovideo.jp/recent?tab=common http://live.nicovideo.jp/recent2onairstreams?sort=&tab=common',
"insertBefore": '',
},
/* "requestFilter": function(opt) {}, */
/* "responseFilter": function (res, url) {}, */
"documentFilter": function (doc, url, siteinfo)
{
changeDoc(doc);
},
/* "filter": function (page) {}, */
}
);
//bootloader
if(!SITEINFO.length) return;
SITEINFO.sort(function(a, b)
{
return b.data.url.length > a.data.url.length;
});
for(var i = 0; i < SITEINFO.length; i++)
{
if(location.href.match(SITEINFO[i].data.url))
{
var match = SITEINFO[i];
break;
}
}
if(!match) return;
window.AutoPagerize? boot(): window.addEventListener('GM_AutoPagerizeLoaded', boot, false);
function boot()
{
if(match.requestFilter)
{
window.AutoPagerize.addRequestFilter(function(opt)
{
match.requestFilter(opt);
});
}
if(match.responseFilter)
{
window.AutoPagerize.addResponseFilter(function(res, url)
{
match.responseFilter(res, url);
});
}
if(match.documentFilter)
{
match.documentFilter(document);
window.AutoPagerize.addDocumentFilter(function(doc, url, siteinfo)
{
match.documentFilter(doc, url, siteinfo);
});
}
if(match.filter)
{
window.AutoPagerize.addFilter(function(page)
{
match.filter(page);
});
}
window.AutoPagerize.launchAutoPager([match.data], true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment