Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <meta content="text/html; charset=UTF-8" http-equiv="Content-Type"></meta>
- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"> </script>
- <script>
- // The code on this page works in a way that it uses info gathered from two pages below (via Wikia API)
- // and write links appeared on the both pages.
- // I wrote it to find untranslated songs in certain languages because wikia search couldn't afford it.
- // I had problems with requesting the said pages by myself, so it's necessary
- // to open the page in browser and save it on a hard disk ( "Ctrl + S " shortcut will make a job).
- //
- // These pages are:
- //
- // http://vocaloidlyrics.wikia.com/api/v1/Articles/List/?limit=10000&category=Pages_in_need_of_English_translation
- // http://vocaloidlyrics.wikia.com/api/v1/Articles/List/?limit=10000&category=Japanese_original_songs
- //
- // You can put another values into limit (it indicates how much pages you want to fetch in one request)
- // and category (like changing language category name; it also works with whitespaces)
- //
- // Then save results on the disk and and put paths to them below (they had to have a file:/// prefix)
- var FILE_1 = "file:///C:/Users/Me/Desktop/pages_in_need.txt";
- var FILE_2 = "file:///C:/Users/Me/Desktop/language_songs.txt";
- // The results can be
- // You can use "wikia" to generate number list of links ready to put into wikia
- // Example: # [["さよなら"は最後だけ。 ("Sayonara" wa Saigo dake.)]]
- // or "html" which write <a> links and it helps with easy navigating from this page to wikia pages.
- // Example: "さよなら"は最後だけ。 ("Sayonara" wa Saigo dake.)
- // (but with blue and a strike below and clickable too)
- var OUTPUT_TYPE = "html";
- // a wikia main site. Used to write proper urls in html output mode.
- var DOMAIN = "http://vocaloidlyrics.wikia.com";
- function mainFirstFunction() {
- var file = FILE_1;
- var rawFile = new XMLHttpRequest();
- rawFile.open("GET", file, false);
- rawFile.onreadystatechange = function ()
- {
- if(rawFile.readyState === 4)
- {
- if(rawFile.status === 200 || rawFile.status == 0)
- {
- var allText = rawFile.responseText;
- var response1 = $.parseJSON(allText);
- getSecondAjax(response1);
- }
- }
- }
- try {
- rawFile.send(null);
- } catch (err) {
- if (err.name === "NS_ERROR_DOM_BAD_URI") {
- alert("ERROR: There's problem with opening a file: " + FILE_1);
- }
- else {
- alert(err);
- }
- }
- }
- function getSecondAjax(response1) {
- var file = FILE_2;
- var rawFile = new XMLHttpRequest();
- rawFile.open("GET", file, false);
- rawFile.onreadystatechange = function ()
- {
- if(rawFile.readyState === 4)
- {
- if(rawFile.status === 200 || rawFile.status == 0)
- {
- var data = rawFile.responseText;
- var response2 = $.parseJSON(data);
- var common = $.grep(response1.items, function(element) {
- return !(response2.items.find(x=> x.id === element.id) === undefined);
- });
- $("#someUrls").empty();
- $.each(common, function (index, value) {
- if (OUTPUT_TYPE === "html") {
- $("#someUrls").append('<a href="' + DOMAIN + value.url + '">' + value.title + '</a> <br />');
- }
- if (OUTPUT_TYPE === "wikia") {
- $("#someUrls").append('# [[' + value.title + ']] <br />');
- }
- });
- }
- }
- }
- try {
- rawFile.send(null);
- } catch (err) {
- if (err.name === "NS_ERROR_DOM_BAD_URI") {
- alert("ERROR: There's problem with opening a file: " + FILE_2);
- }
- else {
- alert(err);
- }
- }
- }
- </script>
- </head>
- <body>
- <button id="button" type="button" onclick="mainFirstFunction()">Find links!</button>
- <p id="someUrls"/>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement