Advertisement
Guest User

page category wikia retriever

a guest
Sep 17th, 2016
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 3.97 KB | None | 0 0
  1. <html>
  2.     <head>
  3.         <meta content="text/html; charset=UTF-8" http-equiv="Content-Type"></meta>
  4.         <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"> </script>
  5.         <script>
  6.            
  7.             //  The code on this page works in a way that it uses info gathered from two pages below (via Wikia API)
  8.             //  and write links appeared on the both pages.
  9.             //  I wrote it to find untranslated songs in certain languages because wikia search couldn't afford it.
  10.             //  I had problems with requesting the said pages by myself, so it's necessary
  11.             //  to open the page in browser and save it on a hard disk ( "Ctrl + S " shortcut will make a job).
  12.             //
  13.             //  These pages are:
  14.             //
  15.             //  http://vocaloidlyrics.wikia.com/api/v1/Articles/List/?limit=10000&category=Pages_in_need_of_English_translation
  16.             //  http://vocaloidlyrics.wikia.com/api/v1/Articles/List/?limit=10000&category=Japanese_original_songs
  17.             // 
  18.             //  You can put another values into limit (it indicates how much pages you want to fetch in one request)
  19.             //  and category (like changing language category name; it also works with whitespaces)
  20.             //
  21.             //  Then save results on the disk and and put paths to them below (they had to have a file:/// prefix)
  22.             var FILE_1 = "file:///C:/Users/Me/Desktop/pages_in_need.txt";
  23.             var FILE_2 = "file:///C:/Users/Me/Desktop/language_songs.txt";
  24.            
  25.             //  The results can be
  26.             //  You can use "wikia" to generate number list of links ready to put into wikia
  27.             //      Example: # [["さよなら"は最後だけ。 ("Sayonara" wa Saigo dake.)]]
  28.             //  or "html" which write <a> links and it helps with easy navigating from this page to wikia pages.
  29.             //      Example: "さよなら"は最後だけ。 ("Sayonara" wa Saigo dake.)
  30.             //      (but with blue and a strike below and clickable too)
  31.             var OUTPUT_TYPE = "html";
  32.            
  33.             //  a wikia main site. Used to write proper urls in html output mode.
  34.             var DOMAIN = "http://vocaloidlyrics.wikia.com";
  35.            
  36.             function mainFirstFunction() {
  37.                
  38.                 var file = FILE_1;
  39.                 var rawFile = new XMLHttpRequest();
  40.                 rawFile.open("GET", file, false);
  41.                 rawFile.onreadystatechange = function ()
  42.                 {
  43.                     if(rawFile.readyState === 4)
  44.                     {
  45.                         if(rawFile.status === 200 || rawFile.status == 0)
  46.                         {
  47.                             var allText = rawFile.responseText;
  48.                             var response1 = $.parseJSON(allText);
  49.                             getSecondAjax(response1);
  50.                         }
  51.                     }
  52.                 }
  53.                 try {
  54.                     rawFile.send(null);
  55.                 } catch (err) {
  56.                     if (err.name === "NS_ERROR_DOM_BAD_URI") {
  57.                         alert("ERROR: There's problem with opening a file: " + FILE_1);
  58.                     }
  59.                     else {
  60.                         alert(err);
  61.                     }
  62.                 }
  63.             }
  64.            
  65.             function getSecondAjax(response1) {
  66.                 var file = FILE_2;
  67.                 var rawFile = new XMLHttpRequest();
  68.                 rawFile.open("GET", file, false);
  69.                 rawFile.onreadystatechange = function ()
  70.                 {
  71.                     if(rawFile.readyState === 4)
  72.                     {
  73.                         if(rawFile.status === 200 || rawFile.status == 0)
  74.                         {
  75.                             var data = rawFile.responseText;
  76.                             var response2 = $.parseJSON(data);
  77.                            
  78.                             var common = $.grep(response1.items, function(element) {
  79.                                 return !(response2.items.find(x=> x.id === element.id) === undefined);
  80.                             });
  81.                             $("#someUrls").empty();
  82.                             $.each(common, function (index, value) {
  83.                                 if (OUTPUT_TYPE === "html") {
  84.                                     $("#someUrls").append('<a href="' + DOMAIN + value.url + '">' + value.title + '</a> <br />');
  85.                                 }
  86.                                 if (OUTPUT_TYPE === "wikia") {
  87.                                     $("#someUrls").append('# [[' + value.title + ']] <br />');
  88.                                 }
  89.                             });
  90.                            
  91.                         }
  92.                     }
  93.                 }
  94.                 try {
  95.                     rawFile.send(null);
  96.                 } catch (err) {
  97.                     if (err.name === "NS_ERROR_DOM_BAD_URI") {
  98.                         alert("ERROR: There's problem with opening a file: " + FILE_2);
  99.                     }
  100.                     else {
  101.                         alert(err);
  102.                     }
  103.                 }
  104.             }
  105.         </script>
  106.     </head>
  107.     <body>
  108.         <button id="button" type="button" onclick="mainFirstFunction()">Find links!</button>
  109.         <p id="someUrls"/>
  110.     </body>
  111. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement