JCCC Library JSON

Using https://library.jccc.edu/home/?newlibrary this script interacts with http://jccc.summon.serialssolutions.com/api/search to get all results as quickly as possible for a particular query. It can handle 1000 results total, because that is where the api cuts it off.

  1. // ==UserScript==
  2. // @name JCCC Library JSON
  3. // @namespace JCCC Library JSON
  4. // @description Using https://library.jccc.edu/home/?newlibrary this script interacts with http://jccc.summon.serialssolutions.com/api/search to get all results as quickly as possible for a particular query. It can handle 1000 results total, because that is where the api cuts it off.
  5. // @include about:blank?jccclibrary
  6. // @include chrome://blank/?library
  7. // @include https://library.jccc.edu/home/?newlibrary
  8. // @match http://jccc.summon.serialssolutions.com/api/*
  9. // @version 0.2
  10. // @grant GM_xmlhttpRequest
  11. // ==/UserScript==
  12. ///////////////////////////////////////////////////////////////
  13. // In order for this script to work in google chrome you must
  14. // have tampermonkey or another script manager that emulates
  15. // the greasemonkey api.
  16. // Reduce default 'referer' header granularity must be enabled
  17. // in chrome://flags
  18. //////////////////////////////////////////////////////////////
  19. var q = '';
  20. var requestTimeout = 100;
  21. var resultsPerPage = 10;
  22.  
  23. var startFuncVar = function () {
  24.  
  25. start();
  26. };
  27. var stopFuncVar = function () {stop();};
  28. //disable all existing stylesheets
  29. for (i=0;i<document.styleSheets.length;i++) {
  30. document.styleSheets[i].disabled=true;
  31.  
  32. }
  33.  
  34. // start with a fresh body
  35. document.body.innerHTML='';
  36. // create de
  37. deciplineSelectElem = document.createElement('select')
  38. deciplineSelectElem.multiple=true
  39. deciplineSelectElem.style.resize="both";
  40. deciplineSelectElem.style.width="28em";
  41. deciplineSelectElem.style.height="10em";
  42. //deciplineSelectElem.style.fontFamily="monospace";
  43. deciplineOptionArray = ["agriculture","anatomy & physiology","anthropology","applied sciences","architecture","astronomy & astrophysics","biology","botany","business","chemistry","computer science","dance","dentistry","diet & clinical nutrition","drama","ecology","economics","education","engineering","environmental sciences","film","forestry","geography","geology","government","history & archaeology","international relations","journalism & communications","languages & literatures","law","library & information science","mathematics","medicine","meteorology & climatology","military & naval science","music","nursing","occupational therapy & rehabilitation","oceanography","parapsychology & occult sciences","pharmacy, therapeutics, & pharmacology","philosophy","physical therapy","physics","political science","psychology","public health","recreation & sports","religion","sciences","social sciences","social welfare & social work","sociology & social history","statistics","veterinary medicine","visual arts","women's studies","zoology"];
  44. newOption=document.createElement("option");
  45. // Create 'any' option
  46. newOption.value='';
  47. newOption.innerHTML='Any';
  48. newOption.selected=true;
  49. deciplineSelectElem.appendChild(newOption);
  50. // loop to populate the decipline select
  51. for (i in deciplineOptionArray) {
  52. newOption=document.createElement("option");
  53. newOption.value=deciplineOptionArray[i];
  54. newOption.innerHTML=deciplineOptionArray[i];
  55. deciplineSelectElem.appendChild(newOption);
  56. }
  57. // start, information, results, and query elements
  58. containerElem = document.createElement("div");
  59. startElem = document.createElement("input");
  60. startElem.setAttribute("value","Start");
  61. startElem.setAttribute("type","button");
  62. startElem.addEventListener("click",startFuncVar,false);
  63.  
  64.  
  65. stopElem = document.createElement("input");
  66. stopElem.setAttribute("value","STOP");
  67. stopElem.setAttribute("type","button");
  68. stopElem.addEventListener("click",stopFuncVar,false);
  69. /*
  70. stopElem = document.createElement("input");
  71. stopElem.setAttribute("value","STOP");
  72. stopElem.setAttribute("type","button");
  73. stopElem.addEventListener("click",function () {
  74. for (j=0;j<timeoutarray.length;j++) {
  75. clearTimeout(timeoutarray[j]);
  76. }
  77. });
  78. */
  79. infoElem = document.createElement("div");
  80. infoElem.style.display="inline";
  81. queryElem = document.createElement("input");
  82. queryElem.setAttribute("type","text");
  83.  
  84.  
  85. stopping=true;
  86. stillrequesting=false;
  87. deciplinechange=false;
  88. var queryNumber = 0;
  89. //queryNumberLast = 0;
  90. //onpage = '<span id="onpage"></span>';
  91. //options = '<select id="categories"><option value="">Any</option><option value="agriculture">agriculture</option><option value="anatomy & physiology">anatomy & physiology</option><option value="anthropology">anthropology</option><option value="applied sciences">applied sciences</option><option value="architecture">architecture</option><option value="astronomy & astrophysics">astronomy & astrophysics</option><option value="biology">biology</option><option value="botany">botany</option><option value="business">business</option><option value="chemistry">chemistry</option><option value="computer science">computer science</option><option value="dance">dance</option><option value="dentistry">dentistry</option><option value="diet & clinical nutrition">diet & clinical nutrition</option><option value="drama">drama</option><option value="ecology">ecology</option><option value="economics">economics</option><option value="education">education</option><option value="engineering">engineering</option><option value="environmental sciences">environmental sciences</option><option value="film">film</option><option value="forestry">forestry</option><option value="geography">geography</option><option value="geology">geology</option><option value="government">government</option><option value="history & archaeology">history & archaeology</option><option value="international relations">international relations</option><option value="journalism & communications">journalism & communications</option><option value="languages & literatures">languages & literatures</option><option value="law">law</option><option value="library & information science">library & information science</option><option value="mathematics">mathematics</option><option value="medicine">medicine</option><option value="meteorology & climatology">meteorology & climatology</option><option value="military & naval science">military & naval science</option><option value="music">music</option><option value="nursing">nursing</option><option value="occupational therapy & rehabilitation">occupational therapy & rehabilitation</option><option value="oceanography">oceanography</option><option value="parapsychology & occult sciences">parapsychology & occult sciences</option><option value="pharmacy, therapeutics, & pharmacology">pharmacy, therapeutics, & pharmacology</option><option value="philosophy">philosophy</option><option value="physical therapy">physical therapy</option><option value="physics">physics</option><option value="political science">political science</option><option value="psychology">psychology</option><option value="public health">public health</option><option value="recreation & sports">recreation & sports</option><option value="religion">religion</option><option value="sciences">sciences</option><option value="social sciences">social sciences</option><option value="social welfare & social work">social welfare & social work</option><option value="sociology & social history">sociology & social history</option><option value="statistics">statistics</option><option value="veterinary medicine">veterinary medicine</option><option value="visual arts">visual arts</option><option value="women\'s studies">women\'s studies</option><option value="zoology">zoology</option></select>';
  92. /*document.body.innerHTML='<input type="text" id="query">'; //<input type="button" value="start" id="start">'+onpage+'<br>'+options+'<br><input type="button" value=" . stop . " id="stop"><span id="total"></span><br>';
  93. q = document.getElementById('query').value;
  94. //document.getElementById('start').addEventListener("click",function () {start();});
  95. */
  96. checkKeyFuncVarisStopped = function (event) {checkkey(event,false);}
  97. checkKeyFuncVarisStarted = function (event) {checkkey(event,true);}
  98. checkMouseFuncVarisStopped = function (event) {checkmouse(false);}
  99. checkMouseFuncVarisStarted = function (event) {checkmouse(true);}
  100. queryElem.addEventListener("keyup",checkKeyFuncVarisStopped);
  101. queryElem.addEventListener("keyup",checkKeyFuncVarisStopped);
  102. startElem.addEventListener("click",checkMouseFuncVarisStopped);
  103. queryElem.addEventListener("keyup",function () {changeButtonText(); });
  104. queryElem.addEventListener("keydown",function () {changeButtonText(); });
  105.  
  106. queryElem.addEventListener("keypress",function () {changeButtonText(); });
  107. deciplineSelectElem.addEventListener("change",function () {
  108. changeButtonText("Start");
  109. deciplinechange=true;
  110. changeButtonText();
  111.  
  112. });
  113. queryElem.accessKey="s";
  114. /*
  115. document.getElementById("stop").addEventListener("click",function () {
  116. for (j=0;j<timeoutarray.length;j++) {
  117. clearTimeout(timeoutarray[j]);
  118. }
  119. });
  120. */
  121. timeoutarray = [];
  122. while (timeoutarray.length>0) {
  123. clearTimeout(timeoutarray.pop());
  124. }
  125.  
  126.  
  127.  
  128.  
  129. //append all elements
  130. containerElem.appendChild(stopElem);
  131. containerElem.appendChild(queryElem);
  132.  
  133. containerElem.appendChild(startElem);
  134.  
  135. containerElem.appendChild(infoElem);
  136.  
  137. document.body.appendChild(containerElem);
  138. //document.body.appendChild(stopElem);
  139. document.body.appendChild(deciplineSelectElem);
  140. queryElem.focus();
  141. function changeButtonText(setText) {
  142. if (setText!=undefined && setText!=null && setText!=NaN) {
  143. startElem.setAttribute("value",setText);
  144. } else {
  145. if (deciplinechange==true) {
  146. startElem.setAttribute("value","Start");
  147. makeStartEvent();
  148. } else {
  149. if (((otherii<(500/resultsPerPage)+1) && q!=queryElem.value) || q=='') {
  150. makeStartEvent();
  151. startElem.setAttribute("value","Start");
  152. } else if ((otherii<(500/resultsPerPage)+1) && q==queryElem.value && stopping==true) {
  153. startElem.setAttribute("value","Resume");
  154. } else if ((otherii<(500/resultsPerPage)+1) && q==queryElem.value && stopping==false) {
  155. startElem.setAttribute("value","Stop");
  156. } else if (q==queryElem.value && requestingdone==true) {
  157. startElem.setAttribute("value","Done");
  158. } else if (stopping=false) {
  159. startElem.setAttribute("value","Stop");
  160. }
  161. }
  162. }
  163.  
  164. }
  165. //setInterval(changeButtonText(),250);
  166. function makeStartEvent() {
  167. startElem.removeEventListener("click",checkMouseFuncVarisStarted);
  168. queryElem.removeEventListener("keyup",checkKeyFuncVarisStarted);
  169. deciplineSelectElem.addEventListener("keyup",checkKeyFuncVarisStarted);
  170. startElem.addEventListener("click",checkMouseFuncVarisStopped);
  171. queryElem.addEventListener("keyup",checkKeyFuncVarisStopped);
  172. deciplineSelectElem.addEventListener("keyup",checkKeyFuncVarisStopped);
  173. }
  174. function makeStopEvent() {
  175. queryElem.removeEventListener("keyup",checkKeyFuncVarisStopped);
  176. startElem.removeEventListener("click",checkMouseFuncVarisStopped);
  177. deciplineSelectElem.removeEventListener("keyup",checkKeyFuncVarisStopped);
  178. queryElem.addEventListener("keyup",checkKeyFuncVarisStarted);
  179. startElem.addEventListener("click",checkMouseFuncVarisStarted);
  180. deciplineSelectElem.addEventListener("keyup",checkKeyFuncVarisStarted);
  181.  
  182. }
  183. function stop() {
  184.  
  185. stopping=true;
  186. while (timeoutarray.length>0) {
  187. clearTimeout(timeoutarray.pop());
  188. }
  189. startElem.setAttribute("value","Start");
  190. if ((otherii<(500/resultsPerPage)+1) && q==queryElem.value) {
  191. startElem.setAttribute("value","Resume");
  192. } else {
  193. startElem.setAttribute("value","Start");
  194. }
  195. startElem.removeEventListener("click",checkMouseFuncVarisStarted);
  196. queryElem.removeEventListener("keyup",checkKeyFuncVarisStarted);
  197. startElem.addEventListener("click",checkMouseFuncVarisStopped);
  198. queryElem.addEventListener("keyup",checkKeyFuncVarisStopped);
  199. //queryElem.addEventListener("keyup",checkKeyFuncVarisStopped);
  200. changeButtonText();
  201. }
  202. function makeDiciplineQuery() {
  203. diciplineQuery="";
  204. //console.log("makediciplinequery");
  205. for (i=0; i<deciplineSelectElem.options.length; i++) {
  206. if (deciplineSelectElem.options[i].selected===true && deciplineSelectElem.options[i].value==='') {
  207. //console.log("break");
  208. break;
  209. }
  210. if (deciplineSelectElem.options[i].selected===true) {
  211. //console.log("selected");
  212. //console.log(typeof(diciplineQuery)+"//q");
  213. //console.log(deciplineSelectElem.options[i]);
  214. diciplineQuery+='&fvf[]=Discipline,'+deciplineSelectElem.options[i].value.replace(/\s/g,'+').replace(/&/g,'%26')+',f';
  215. //console.log(typeof(diciplineQuery)+"//q");
  216. }
  217. }
  218. return diciplineQuery;
  219. }
  220.  
  221. function start() {
  222.  
  223. while (timeoutarray.length>0) {
  224. //alert(timeoutarray.length);
  225. clearTimeout(timeoutarray.pop());
  226. }
  227. stopping=false;
  228. if ((otherii<(500/resultsPerPage)+1) && q==queryElem.value && deciplinechange==false) {
  229. timeoutarray[timeoutarray.length]=setTimeout(apireq(otherii,queryNumber),0);
  230. changeButtonText("Stop");
  231. makeStopEvent();
  232.  
  233. }
  234.  
  235. if (q==queryElem.value && deciplinechange==false) {
  236. return false;
  237. }
  238. //queryElem.removeEventListener("keyup",checkKeyFuncVarisStopped);
  239. //sstartElem.removeEventListener("click",checkMouseFuncVarisStopped);
  240. //queryElem.removeEventListener("keyup",checkKeyFuncVarisStopped);
  241. //queryElem.addEventListener("keyup",checkKeyFuncVarisStarted);
  242. //startElem.addEventListener("click",checkMouseFuncVarisStarted)
  243. //queryElem.addEventListener("keyup",checkKeyFuncVarisStarted);
  244.  
  245. makeStopEvent();
  246.  
  247. deciplinechange=false;
  248. allResults = document.getElementsByClassName("resultdiv");
  249. while (allResults.length>0) {
  250.  
  251. document.body.removeChild(allResults[0]);
  252. }
  253.  
  254.  
  255. startElem.setAttribute("value","STOP");
  256. //startElem.removeEventListener("click",startFuncVar,false);
  257. //startElem.addEventListener("click",stopFuncVar,false);
  258. //deciplineQuery="";
  259. stopping=true;
  260. //q = document.getElementById('query').value;
  261. q = queryElem.value;
  262. /*
  263. for (i=0; i<deciplineSelectElem.options.length; i++) {
  264. if (deciplineSelectElem.options[i].selected===true && deciplineSelectElem.options[i].value==='') {
  265. break;
  266. }
  267. if (deciplineSelectElem.options[i].selected===true) {
  268. //console.log(deciplineSelectElem.options[i]);
  269. deciplineQuery+='&fvf[]=Discipline,'+deciplineSelectElem.options[i].value.replace(/\s/g,'+').replace(/&/g,'%26')+',f'
  270. }
  271. }
  272. */
  273. deciplineQuery=makeDiciplineQuery();
  274. console.log(deciplineQuery);
  275.  
  276. //decipline = '&fvf[]=Discipline,'+decipline.replace(/\s/g,'+').replace(/&/g,'%26')+',f';
  277. //document.body.innerHTML+='<input type="text" id="query">'
  278. //document.body.innerHTML='<input type="text" id="query" value="'+q.replace(/"/g,'&quot;')+'"><input type="button" value="start" id="start">'+onpage+'<br>'+options+'<br><input type="button" value=" . stop . " id="stop"><span id="total"></span><br>';
  279. //document.getElementById('start').addEventListener("click",function () {start();});
  280. //document.getElementById('query').addEventListener("keydown",function (event) {checkkey(event);});
  281. //document.getElementById('query').addEventListener("keyup",function (event) {checkkey(event);});
  282. //document.getElementById("stop").addEventListener("click",function () {
  283. //for (j=0;j<timeoutarray.length;j++) {
  284. // clearTimeout(timeoutarray[j]);
  285. //}
  286. //stopping=true;
  287. //});
  288. /*
  289. alloptions = document.getElementsByTagName("option");
  290. for (o in alloptions) {
  291. if (alloptions[o].value==decipline) {
  292. alloptions[o].selected=true;
  293. }
  294. }
  295. */
  296. ii=1;
  297. otherii=1;
  298. totalpages = 51;
  299. linksarray = [];
  300. function linksa(link) {
  301. linksarray.push(link);
  302. }
  303. arrayi = [];
  304. for (i=0;i<totalpages;i++) {
  305. arrayi[i]=i;
  306. }
  307. i=0;
  308. for (j=0;j<timeoutarray.length;j++) {
  309. clearTimeout(timeoutarray[j]);
  310. }
  311. //for (i=0;i<totalpages;i++) {
  312.  
  313. //timeoutarray[i]=setTimeout(function (i) {
  314. stopping=false;
  315. requestingdone=false;
  316. resultnumber = 0;
  317. //document.getElementById("onpage").innerHTML="Requesting Page 1";
  318. queryNumber++;
  319. timeoutarray[timeoutarray.length]=setTimeout(apireq(ii,queryNumber),0);
  320. //apireqsingle(1);
  321.  
  322. //},(timeoutForEachRequest*arrayi.shift()));
  323.  
  324.  
  325. //}
  326. }
  327.  
  328. var otherii;
  329. var otherii2;
  330. var resultnumber = 0;
  331. function apireq(ii,queryNumberF) {
  332.  
  333. infoElem.innerHTML=" Requesting Page "+ii;
  334. GM_xmlhttpRequest({
  335. method: "GET",
  336. url: 'http://jccc.summon.serialssolutions.com/api/search?pn='+(ii)+'&ho=t'+deciplineQuery+'&fvf[]=IsFullText,true,f&l=en&ps='+resultsPerPage+'&q='+q,
  337. data: "",
  338. headers: {
  339. "Host": "jccc.summon.serialssolutions.com",
  340. "User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:37.0) Gecko/20100101 Firefox/37.0",
  341. "Accept": "application/json, text/plain, */*",
  342. "Accept-Language": "en-US,en;q=0.5",
  343. "Accept-Encoding": "gzip, deflate",
  344. "SUMMON_SID": "",
  345. "Referer": "http://jccc.summon.serialssolutions.com/search",
  346. "Cookie": "Summon-Two=true; hasSavedItems=1",
  347. "Connection": "keep-alive"
  348. },
  349. onload: function(response) {
  350. if (queryNumberF==queryNumber) {
  351. console.log('onload');
  352. //document.body.innerHTML="<pre>"+response.responseText+"</pre>"
  353. pages = JSON.parse(response.responseText);
  354. //document.body.innerHTML="<pre>"+pages.full_text_link+"</pre>";
  355. //document.body.innerHTML="";
  356. /*
  357. findobj = pages;
  358. for (key in findobj) {
  359. document.body.innerHTML+="<br>"+key+":\n"+findobj[key]+"<br>";
  360. }
  361. */
  362. if (pages.documents=='') {
  363. requestingdone=true;
  364. }
  365. //document.getElementById("total").innerHTML=" Total Records "+pages.record_count;
  366. for (key in pages.documents) {
  367. resultnumber++;
  368. //console.log(resultnumber);
  369. newh3 = document.createElement("h3");
  370. newh3.setAttribute("class","result");
  371. newh3.innerHTML=pages.documents[key]["full_title"];
  372. newh3.style.display="inline";
  373. newh4 = document.createElement("h4");
  374. newh4.setAttribute("class","result");
  375. if (resultnumber<10) {
  376. zeros="00";
  377. } else if (resultnumber<100) {
  378. zeros="0";
  379. } else {
  380. zeros="";
  381. }
  382. newh4.innerHTML=zeros+resultnumber+" ";
  383. newh4.style.display="inline-block";
  384. //newh4.style.height="100%";
  385. //newh4.style.width="3em";
  386. newh4.style.margin="0";
  387. newh4.style.paddingRight="1em";
  388. newdiv2 = newdiv = document.createElement("div");
  389. newa = document.createElement("a");
  390. newa.setAttribute("class","result");
  391. newa.setAttribute("href",pages.documents[key]["fulltext_link"]);
  392. newa.appendChild(newh3);
  393. newspan2 = document.createElement("span");
  394. if (pages.documents[key]["publication_title"]!=undefined) {
  395. newspan2.innerHTML = ' &rarr; '+pages.documents[key]["publication_title"];
  396. }
  397. if (pages.documents[key]["publisher"]!=undefined) {
  398. newspan2.innerHTML += ' &rarr; '+pages.documents[key]["publisher"];
  399. }
  400. newspan2.style.fontStyle="italic";
  401. newdiv2.appendChild(newh4);
  402. newdiv2.appendChild(newa);
  403. newdiv2.appendChild(newspan2);
  404. newa.style.display="inline";
  405. newdiv = document.createElement("div");
  406. newdiv.setAttribute("class",ii);
  407. //newdiv.innerHTML=pages.documents[key]["snippet"];
  408. newdiv.style.padding="2px";
  409. newdiv2.style.padding="2px";
  410. newdiv2.style.borderTop="1px solid #000000";
  411. newdiv.setAttribute("class","result");
  412. newdiv2.setAttribute("class","resultdiv");
  413. if ((resultnumber%2)==0) {
  414. newdiv2.style.backgroundColor="#e9e9e9";
  415. newdiv.style.backgroundColor="#e9e9e9";
  416. }
  417. document.body.appendChild(newdiv2);
  418. newspan = document.createElement("span");
  419. newspan.setAttribute("class","result");
  420. if (pages.documents[key]["snippet"]==undefined) {
  421. newspan.innerHTML=''
  422. } else {
  423. newspan.innerHTML=pages.documents[key]["snippet"];
  424. }
  425. newspan.style.paddingLeft="1em";
  426. newdiv.appendChild(newspan);
  427. newdiv2.appendChild(newdiv);
  428. //document.body.innerHTML+='<h3>'+pages.documents[key]["full_title"]+'</h3><br><a href="'+pages.documents[key]["fulltext_link"]+'">'+pages.documents[key]["fulltext_link"]+'</a><br>'+pages.documents[key]["snippet"]+"<br><br>";
  429. }
  430. /*
  431. console.log(ii+","+q+","+decipline.replace(/\s/g,'+'));
  432. if (ii<20) {
  433. document.getElementById("onpage").innerHTML="Last Requested Page "+ii;
  434. } else {
  435. document.getElementById("onpage").innerHTML="Requesting Done Page "+ii;
  436. //alert("'"+pages.documents+"'");
  437. }
  438. if (requestingdone==true) {
  439. document.getElementById("onpage").innerHTML="Requesting Done Page "+ii;
  440. }
  441. */
  442. otherii = (ii+1);
  443. if (otherii<(500/resultsPerPage)+1 && stopping==false && requestingdone==false) {
  444. if (requestingdone==false) {
  445.  
  446. //////////////////////// timeout recursive download ////////////////////////
  447. console.log("queryNumberF "+queryNumberF);
  448. timeoutarray[timeoutarray.length]=setTimeout(apireq(otherii,queryNumberF),requestTimeout);
  449.  
  450.  
  451.  
  452. }
  453. } else {
  454. stop();
  455. infoElem.innerHTML=" Stopped Requesting on Page "+ii;
  456. }
  457. if (requestingdone==true) {
  458. stop();
  459. infoElem.innerHTML=" Done Requesting on Page "+ii;
  460. }
  461. }
  462. }
  463. });
  464.  
  465. }
  466.  
  467. function checkkey(event,isStarted) {
  468. thekey = event.which || event.keyCode;
  469. if (thekey==13 && isStarted==false) {
  470. console.log("1");
  471. start();
  472. return true;
  473. }
  474. if (thekey==13 && isStarted==true) {
  475. console.log("2");
  476. stop();
  477. return true;
  478. }
  479. }
  480.  
  481. function checkmouse(isStarted) {
  482. if (isStarted==true) {
  483. console.log("3");
  484. stop();
  485. return true;
  486. }
  487.  
  488. if (isStarted==false) {
  489. console.log("4");
  490. start();
  491. return true;
  492. }
  493. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址