-
-
Save awq/554710 to your computer and use it in GitHub Desktop.
Add AutoPager function to PubMed result page
This file contains 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 ap suppl PubMed | |
// @namespace http://d.hatena.ne.jp/awq/ | |
// @include http://www.ncbi.nlm.nih.gov/pubmed* | |
// @include http://www.ncbi.nlm.nih.gov/sites/entrez* | |
// @description Add AutoPager function to PubMed result page | |
// ==/UserScript== | |
/***** | |
-Requirement | |
This script requires pre-installed autopagerize.user.js by swdyh (http://autopagerize.net/). | |
-Acknowledgement | |
This script was created, inspired by Pubmed Autopager by Tamapiyo1 (https://addons.mozilla.org/ja/firefox/addon/10998/). | |
*****/ | |
var SITEINFO = []; | |
SITEINFO.push( | |
{ | |
"name": 'PubMed', | |
"data": | |
{ | |
"url": '^http://www\.ncbi\.nlm\.nih\.gov/(?:pubmed|sites/entrez)', | |
"nextLink": 'id("maincontent")/div[@class="title_and_pager"][last()]/div[@class="pagination"]/a[contains(@class,"next")]', | |
"pageElement": 'id("maincontent")/div[not(@class)]', | |
"exampleUrl": 'http://www.ncbi.nlm.nih.gov/pubmed http://www.ncbi.nlm.nih.gov/sites/entrez', | |
"insertBefore": '', | |
}, | |
"requestFilter": function(opt) | |
{ | |
var postDataStr = '', postData = window.AutoPagerize.postData; | |
for(name in postData) postDataStr += name + '=' + postData[name] + '&'; | |
opt.method = 'POST'; | |
opt.headers = {'Content-type': 'application/x-www-form-urlencoded'}; | |
opt.data = postDataStr; | |
}, | |
/* "responseFilter": function(res, url) {}, */ | |
"documentFilter": function(doc, url, siteinfo) | |
{ | |
if(!window.AutoPagerize.postData) | |
{ | |
postData = window.AutoPagerize.postData = {}; | |
var elems = doc.forms[0].elements; | |
for(var i = 0, l = elems.length; i < l; i++) | |
{ | |
if( | |
elems[i].name && !(elems[i].disabled) | |
&& (elems[i].type != 'radio' && elems[i].type != 'checkbox' || elems[i].checked==true) | |
) | |
{ | |
postData[escape(elems[i].name)] = elems[i].value? escape(elems[i].value): ''; | |
} | |
} | |
postData["EntrezSystem2.PEntrez.DbConnector.Cmd"] = "PageChanged"; | |
} | |
var nextLink = doc.evaluate(this.data.nextLink, doc, null, 9, null).singleNodeValue; | |
if(nextLink) | |
{ | |
nextLink.href += window.AutoPagerize.postData["EntrezSystem2.PEntrez.Pubmed.Pubmed_ResultsPanel.Entrez_Pager.CurrPage"] | |
= nextLink.getAttribute('page'); | |
} | |
}, | |
"filter": function(page) | |
{ | |
var apPageInfoLink = document.evaluate('id("maincontent")/p[@class="autopagerize_page_info"][last()]/a', document, null, 9, null).singleNodeValue; | |
var pg = apPageInfoLink.href.match(/\d+$/)[0]; | |
apPageInfoLink.href = '#'; | |
apPageInfoLink.addEventListener('click', function() | |
{ | |
document.getElementsByName("EntrezSystem2.PEntrez.Pubmed.Pubmed_ResultsPanel.Entrez_Pager.CurrPage")[0].value = pg; | |
document.getElementsByName("EntrezSystem2.PEntrez.DbConnector.Cmd")[0].value = 'PageChanged'; | |
document.forms[0].submit(); | |
}, false); | |
}, | |
} | |
); | |
/* 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