Skip to content

Instantly share code, notes, and snippets.

@awq
Created September 24, 2010 02:03
Show Gist options
  • Save awq/594745 to your computer and use it in GitHub Desktop.
Save awq/594745 to your computer and use it in GitHub Desktop.
Add AutoPager function to Nojiri Board
// ==UserScript==
// @name ap suppl Nojiri Board
// @namespace http://d.hatena.ne.jp/awq/
// @include http://njb.virtualave.net/nmain*
// @description Add AutoPager function to Nojiri Board
// ==/UserScript==
/*****
-Requirement
This script requires pre-installed autopagerize.user.js by swdyh (http://autopagerize.net/).
*****/
var SITEINFO = [];
SITEINFO.push(
{
"name": '野尻ボード',
"data": {
"url": '^http://njb\.virtualave\.net/nmain(?:\\d+)?\.html',
"nextLink": '//h2/a',
"pageElement": '//*[preceding-sibling::hr][not(preceding-sibling::ul)]',
"exampleUrl": 'http://njb.virtualave.net/nmain.html',
"insertBefore": '',
},
/* "requestFilter": function (opt) {}, */
/* "responseFilter": function (res, url) {}, */
"documentFilter":function(doc) {
var snapshot = doc.evaluate('//nobr/li/a', doc, null, 7, null);
for(var i = 0, l = snapshot.snapshotLength; i < l; i++){
a = snapshot.snapshotItem(i);
a.href = '#' + a.name;
a.removeAttribute('name');
a.removeAttribute('target');
}
}
/* "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];
debug(match.data.url);
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