Advertisement
ValerioLyndon

BurntJello Bookmarklet temp engtitle

Mar 9th, 2021
816
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. javascript: /* MyAnimeList CSS Generator and Tags updater
  2. - Original code   2018/Aug/10 by BurntJello http://burntjello.webs.com
  3. - Extra features  2019        by Cateinya
  4. - Fixes           2020/Oct    by Cry5talz
  5. - Further changes 2021+       by Valerio Lyndon
  6. */
  7. /* modify these to change your defaults */
  8. CSS_TEMPLATE = '.data.title .link[href^="/anime/[ID]/"]{font-size:0!important;}.title a[href^="/anime/[ID]/"]:after{content:"[ENGTITLE]";}';
  9. MATCH_TEMPLATE = "/anime/[ID]/";
  10. DELAY = "500";
  11. CHECK_EXISTING = false;
  12. UPDATE_TAGS = false;
  13. TAGS_ENGLISH_TITLE = false;
  14. TAGS_SEASON = false;
  15. TAGS_YEAR = false;
  16. TAGS_STUDIO = false;
  17. TAGS_GENRES = false;
  18. TAGS_PRODUCERS = false;
  19. TAGS_AIRED = false;
  20. TAGS_SCORE = false;
  21. TAGS_RANK = false;
  22.  
  23.  
  24. /* CSS_TEMPLATE = "[ID] | [TITLE] | [ENGTITLE] | [IMGURL] | [GENRES] | [STUDIOS] | [PRODUCERS] | [SEASON] | [YEAR] | [RANK] | [SCORE] | [STARTDATE] | [ENDDATE] | [DESC]"; */
  25.  
  26. /* defines the start of certain sections on the anime page */
  27. ENGLISH_START = "English:</span>";
  28. SYN_START = "Synonyms:</span>";
  29. GENRES_START = "Genres:</span>";
  30. DESC_START = "Synopsis</h2>";
  31. RANK_START = "Ranked:</span>";
  32. SCORE_SELECTOR = "[itemprop=\"ratingValue\"]";
  33.  
  34. /* Anime page only */
  35. STUDIOS_START = "Studios:</span>";
  36. PRODUCERS_START = "Producers:</span>";
  37. AIRED_START = "Aired:</span>";
  38.  
  39. /* Manga page only */
  40. PUBLISHED_START = "Published:</span>";
  41. AUTHORS_START = "Authors:</span>"; /* (To be added) */
  42. SERIALIZATION_START = "Serialization:</span>"; /* (To be added) */
  43.  
  44. /* tool code */
  45. moreIds = new Array();
  46. modernStyle = (document.getElementById("list_surround")) ? false : true;
  47.  
  48. tempDiv = document.createElement("div");
  49. document.body.appendChild(tempDiv);
  50. tempDiv.style.position = "fixed";
  51. tempDiv.style.left = "50px";
  52. tempDiv.style.top = "50px";
  53. tempDiv.style.bottom = "50px";
  54. tempDiv.style.right = "50px";
  55. tempDiv.style.backgroundColor = "#FFFFFF";
  56. tempDiv.style.borderStyle = "solid";
  57. tempDiv.style.zIndex = "99999";
  58.  
  59. thumbBtn = document.createElement("input");
  60. tempDiv.appendChild(thumbBtn);
  61. thumbBtn.type = "button";
  62. thumbBtn.value = "Start";
  63.  
  64. statusText = document.createElement("span");
  65. tempDiv.appendChild(statusText);
  66. statusText.style.color = "#000000";
  67.  
  68. delay = document.createElement("input");
  69. tempDiv.appendChild(delay);
  70. delay.type = "text";
  71. delay.value = DELAY;
  72. delay.style.width = "50px";
  73. delay.title = "Delay (ms) between requests to avoid spamming the server.";
  74.  
  75. matchTemplate = document.createElement("input");
  76. tempDiv.appendChild(matchTemplate);
  77. matchTemplate.type = "text";
  78. matchTemplate.value = MATCH_TEMPLATE;
  79. matchTemplate.title = "Line matching template.  Only matching on [ID] is not enough, include previous\/next characters to ensure the match is unique.";
  80.  
  81. template = document.createElement("input");
  82. tempDiv.appendChild(template);
  83. template.type = "text";
  84. template.value = CSS_TEMPLATE;
  85. template.style.width = "50%";
  86. template.title = "CSS template.  Replacements are [ID], [IMGURL], [IMGURLT], [IMGURLV], [TITLE], [ENGTITLE], [GENRES], [STUDIOS], [PRODUCERS], [SEASON], [YEAR], [RANK], [SCORE], [STARTDATE], [ENDDATE], and [DESC]. ([DEL] will just be deleted)";
  87.  
  88. chkExistingLabel = document.createElement("span");
  89. tempDiv.appendChild(chkExistingLabel);
  90. chkExistingLabel.style.color = "#000000";
  91. chkExistingLabel.appendChild(document.createTextNode(" Check Existing Images:"));
  92.  
  93. chkExisting = document.createElement("input");
  94. tempDiv.appendChild(chkExisting);
  95. chkExisting.type = "checkbox";
  96. chkExisting.title = "Attempt to load all images, updating the url if it fails. There is a 5 second delay to allow images to load.  I do not recommend using this while adding new anime or updating tags!";
  97. chkExisting.checked = CHECK_EXISTING;
  98.  
  99. exitBtn = document.createElement("input");
  100. tempDiv.appendChild(exitBtn);
  101. exitBtn.type = "button";
  102. exitBtn.value = "Exit";
  103.  
  104. br1 = document.createElement("br");
  105. tempDiv.appendChild(br1);
  106.  
  107. chkTags = document.createElement("input");
  108. tempDiv.appendChild(chkTags);
  109. chkTags.type = "checkbox";
  110. chkTags.title = "Update Tags";
  111. chkTags.checked = UPDATE_TAGS;
  112.  
  113. tagsLabel = document.createElement("span");
  114. tempDiv.appendChild(tagsLabel);
  115. tagsLabel.style.color = "#000000";
  116. tagsLabel.appendChild(document.createTextNode("Update Tags:"));
  117.  
  118. chkEnglish = document.createElement("input");
  119. tempDiv.appendChild(chkEnglish);
  120. chkEnglish.type = "checkbox";
  121. chkEnglish.title = "English title";
  122. chkEnglish.checked = TAGS_ENGLISH_TITLE;
  123.  
  124. chkSeason = document.createElement("input");
  125. tempDiv.appendChild(chkSeason);
  126. chkSeason.type = "checkbox";
  127. chkSeason.title = "Season";
  128. chkSeason.checked = TAGS_SEASON;
  129.  
  130. chkYear = document.createElement("input");
  131. tempDiv.appendChild(chkYear);
  132. chkYear.type = "checkbox";
  133. chkYear.title = "Year";
  134. chkYear.checked = TAGS_YEAR;
  135.  
  136. chkStudio = document.createElement("input");
  137. tempDiv.appendChild(chkStudio);
  138. chkStudio.type = "checkbox";
  139. chkStudio.title = "Studio";
  140. chkStudio.checked = TAGS_STUDIO;
  141.  
  142. chkGenres = document.createElement("input");
  143. tempDiv.appendChild(chkGenres);
  144. chkGenres.type = "checkbox";
  145. chkGenres.title = "Genres";
  146. chkGenres.checked = TAGS_GENRES;
  147.  
  148. chkProducers = document.createElement("input");
  149. tempDiv.appendChild(chkProducers);
  150. chkProducers.type = "checkbox";
  151. chkProducers.title = "Producers";
  152. chkProducers.checked = TAGS_PRODUCERS;
  153.  
  154. chkAired = document.createElement("input");
  155. tempDiv.appendChild(chkAired);
  156. chkAired.type = "checkbox";
  157. chkAired.title = "Aired";
  158. chkAired.checked = TAGS_AIRED;
  159.  
  160. chkScore = document.createElement("input");
  161. tempDiv.appendChild(chkScore);
  162. chkScore.type = "checkbox";
  163. chkScore.title = "Score";
  164. chkScore.checked = TAGS_SCORE;
  165.  
  166. chkRank = document.createElement("input");
  167. tempDiv.appendChild(chkRank);
  168. chkRank.type = "checkbox";
  169. chkRank.title = "Rank";
  170. chkRank.checked = TAGS_RANK;
  171.  
  172. existing = document.createElement("textarea");
  173. tempDiv.appendChild(existing);
  174. existing.style.height = "30%";
  175. existing.style.width = "95%";
  176. existing.style.display = "block";
  177. existing.title = "Copy existing thumbnail/description styles here.  The style for one anime ID must all be on the same line.";
  178.  
  179. result = document.createElement("textarea");
  180. tempDiv.appendChild(result);
  181. result.style.height = "50%";
  182. result.style.width = "95%";
  183. result.style.display = "block";
  184. result.title = "Updated styles are written here.";
  185. result.readOnly = "readonly";
  186.  
  187. errorCount = 0;
  188. i = 0;
  189. function ProcessNext()
  190. {
  191.     if(i < moreIds.length)
  192.     {
  193.         moreId = moreIds[i];
  194.        
  195.         try
  196.         {
  197.             animeManga = window.location.href.replace("https://myanimelist.net/", "").split("/")[0].replace("list", "");
  198.             id = moreId.replace("more", "");
  199.             url = "https://myanimelist.net/" + animeManga + "/" + id;
  200.  
  201.             request = new XMLHttpRequest();
  202.             request.open("get", url, false);
  203.             request.send(null);
  204.             str = request.responseText;
  205.             doc = new DOMParser().parseFromString(request.responseText, "text/html");
  206.        
  207.             /* tags */
  208.             tags = new Array();
  209.             if(chkTags.checked)
  210.             {
  211.                 if(modernStyle)
  212.                 {
  213.                     tagEl = document.getElementsByClassName("tags-" + id);
  214.                     if(tagEl.length > 0)
  215.                     {
  216.                         tagEl = tagEl[0].children;
  217.                         for(j = 0; j< tagEl.length; j++) { tags.push(tagEl[j].getElementsByTagName("a")[0].textContent); }
  218.                     }
  219.                     else
  220.                     {
  221.                         alert('Tags are not shown on your list!\n\nPlease uncheck the "Update tags" box, or check the "Tags" box at https://myanimelist.net/editprofile.php?go=listpreferences and try again.');
  222.                     }
  223.                    
  224.                 }
  225.                 else
  226.                 {
  227.                     tagEl = document.getElementById("tagRow" + id);
  228.                     if(tagEl)
  229.                     {
  230.                         tags = tagEl.innerHTML.split(",");
  231.                     }
  232.                     else
  233.                     {
  234.                         alert('Tags are not shown on your list!\n\nPlease uncheck the "Update tags" box, or check the "Tags" box at https://myanimelist.net/editprofile.php?go=listpreferences and try again.');
  235.                     }
  236.                 }
  237.             }
  238.             tagsLength = tags.length;
  239.            
  240.             for(j = 0; j < tagsLength; j++)
  241.             {
  242.                 tags[j] = tags[j].replace(/^\s+|\s+$/g, "");
  243.             }
  244.            
  245.             /* english title */
  246.             englishHtml = null;
  247.             englishHtmlStartIndex = str.indexOf(ENGLISH_START);
  248.             if(str.indexOf(ENGLISH_START) != -1)
  249.             {
  250.                 englishHtmlStartIndex += ENGLISH_START.length;
  251.                 englishHtmlEndIndex = str.indexOf("</div>", englishHtmlStartIndex);
  252.                 englishHtml = str.substring(englishHtmlStartIndex, englishHtmlEndIndex);
  253.                
  254.                 englishHtml = englishHtml.replace(/^\s+|\s+$/g, "").replace(/,/g, "");
  255.                 function HtmlDencode(s)
  256. {
  257.   return s.replace(/&#(\d+);/g, function(match, dec) {
  258.                 return String.fromCharCode(dec);
  259.             });
  260. }
  261. englishHtml = HtmlDencode(englishHtml);
  262.                 englishUpper = englishHtml.toUpperCase();
  263.                 for(k = 0; k < tagsLength; k++)
  264.                 {
  265.                     if(tags[k].length == 0 || tags[k].toUpperCase() == englishUpper)
  266.                     {
  267.                         tags.splice(k, 1);
  268.                         tagsLength--;
  269.                         k--;
  270.                     }
  271.                 }
  272.             }
  273.            
  274.             /* synonyms */
  275.             if(englishHtml == null)
  276.             {
  277.                 synHtmlStartIndex = str.indexOf(SYN_START);
  278.                 if(str.indexOf(SYN_START) != -1)
  279.                 {
  280.                     synHtmlStartIndex += SYN_START.length;
  281.                     synHtmlEndIndex = str.indexOf("</div>", synHtmlStartIndex);
  282.                     synHtml = str.substring(synHtmlStartIndex, synHtmlEndIndex);
  283.                     synArr = synHtml.split(",");
  284.                     if(synArr.length > 0)
  285.                     {
  286.                         englishHtml = synArr[0].replace(/^\s+|\s+$/g, "");
  287.                         synUpper = englishHtml.toUpperCase();
  288.                         for(k = 0; k < tagsLength; k++)
  289.                         {
  290.                             if(tags[k].length == 0 || tags[k].toUpperCase() == synUpper)
  291.                             {
  292.                                 tags.splice(k, 1);
  293.                                 tagsLength--;
  294.                                 k--;
  295.                             }
  296.                         }
  297.                     }
  298.                 }
  299.             }
  300.            
  301.             /* date */
  302.             season = null;
  303.             year = null;
  304.             DATE_START = ( animeManga == "anime" ) ? AIRED_START : PUBLISHED_START;
  305.             dateHtmlStartIndex = str.indexOf(DATE_START) + DATE_START.length;
  306.             if(str.indexOf(DATE_START) != -1)
  307.             {
  308.                 dateHtmlEndIndex = str.indexOf("</div>", dateHtmlStartIndex);
  309.                 dateHtml = str.substring(dateHtmlStartIndex, dateHtmlEndIndex);
  310.                 dateArr = dateHtml.split(" to ");
  311.                 date1Arr = dateArr[0].split(",");
  312.                 if(date1Arr.length == 2)
  313.                 {
  314.                     season = null;
  315.                     if(date1Arr[0].indexOf("Jan") != -1 || date1Arr[0].indexOf("Feb") != -1 || date1Arr[0].indexOf("Mar") != -1)
  316.                     {
  317.                         season = "Winter";
  318.                     }
  319.                     if(date1Arr[0].indexOf("Apr") != -1 || date1Arr[0].indexOf("May") != -1 || date1Arr[0].indexOf("Jun") != -1)
  320.                     {
  321.                         season = "Spring";
  322.                     }
  323.                     if(date1Arr[0].indexOf("Jul") != -1 || date1Arr[0].indexOf("Aug") != -1 || date1Arr[0].indexOf("Sep") != -1)
  324.                     {
  325.                         season = "Summer";
  326.                     }
  327.                     if(date1Arr[0].indexOf("Oct") != -1 || date1Arr[0].indexOf("Nov") != -1 || date1Arr[0].indexOf("Dec") != -1)
  328.                     {
  329.                         season = "Fall";
  330.                     }
  331.                     year = date1Arr[1].replace(/^\s+|\s+$/g, "");
  332.                     for(k = 0; k < tagsLength; k++)
  333.                     {
  334.                         if(tags[k].length == 0 || tags[k].toUpperCase() == season.toUpperCase() || tags[k] == year)
  335.                         {
  336.                             tags.splice(k, 1);
  337.                             tagsLength--;
  338.                             k--;
  339.                         }
  340.                     }
  341.                 }
  342.             }
  343.            
  344.             /* studio (anime) */
  345.             studios = null;
  346.             studiosHtmlStartIndex = str.indexOf(STUDIOS_START);
  347.             if(str.indexOf(STUDIOS_START) != -1)
  348.             {
  349.                 studiosHtmlStartIndex += STUDIOS_START.length;
  350.                 studiosHtmlEndIndex = str.indexOf("</div>", studiosHtmlStartIndex);
  351.                 studiosHtml = str.substring(studiosHtmlStartIndex, studiosHtmlEndIndex);
  352.                
  353.                 studios = studiosHtml.split(",");
  354.                 studiosLength = studios.length;
  355.                 for(j = 0; j < studiosLength; j++)
  356.                 {
  357.                     g1 = studios[j].indexOf("\">") + 2;
  358.                     g2 = studios[j].indexOf("</a>");
  359.                     if(g2 == -1) { studios = null; break; }
  360.                     studios[j] = studios[j].substring(g1, g2).replace(/^\s+|\s+$/g, "");
  361.                     studioUpper = studios[j].toUpperCase();
  362.                    
  363.                     for(k = 0; k < tagsLength; k++)
  364.                     {
  365.                         if(tags[k].length == 0 || tags[k].toUpperCase() == studioUpper)
  366.                         {
  367.                             tags.splice(k, 1);
  368.                             tagsLength--;
  369.                             k--;
  370.                         }
  371.                     }
  372.                 }
  373.             }
  374.            
  375.             /* producers (anime) */
  376.             producers = null;
  377.             producersHtmlStartIndex = str.indexOf(PRODUCERS_START);
  378.             if(str.indexOf(PRODUCERS_START) != -1)
  379.             {
  380.                 producersHtmlStartIndex += PRODUCERS_START.length;
  381.                 producersHtmlEndIndex = str.indexOf("</div>", producersHtmlStartIndex);
  382.                 producersHtml = str.substring(producersHtmlStartIndex, producersHtmlEndIndex);
  383.    
  384.                 producers = producersHtml.split(",");
  385.                 producersLength = producers.length;
  386.                 for(j = 0; j < producersLength; j++)
  387.                 {
  388.                     if(producers[j].indexOf("<sup>") == -1)
  389.                     {
  390.                         g1 = producers[j].indexOf("\">") + 2;
  391.                         g2 = producers[j].indexOf("</a>");
  392.                         if(g2 == -1) { producers = null; break; }
  393.                         producers[j] = producers[j].substring(g1, g2).replace(/^\s+|\s+$/g, "");
  394.                         studioUpper = producers[j].toUpperCase();
  395.                        
  396.                         for(k = 0; k < tagsLength; k++)
  397.                         {
  398.                             if(tags[k].length == 0 || tags[k].toUpperCase() == studioUpper)
  399.                             {
  400.                                 tags.splice(k, 1);
  401.                                 tagsLength--;
  402.                                 k--;
  403.                             }
  404.                         }
  405.                     }
  406.                     else
  407.                     {
  408.                         producers.splice(j, 1);
  409.                         producersLength--;
  410.                         j--;
  411.                     }
  412.                 }
  413.             }
  414.            
  415.             /* genres */
  416.             genres = null;
  417.             genresHtmlStartIndex = str.indexOf(GENRES_START);
  418.             if(str.indexOf(GENRES_START) != -1)
  419.             {
  420.                 genresHtmlStartIndex += RANK_START.length;
  421.                 genresHtmlEndIndex = str.indexOf("</div>", genresHtmlStartIndex);
  422.                 genresHtml = str.substring(genresHtmlStartIndex, genresHtmlEndIndex);
  423.                
  424.                 genres = genresHtml.split(",");
  425.                 genresLength = genres.length;
  426.                 for(j = 0; j < genresLength; j++)
  427.                 {
  428.                     genres[j] = genres[j].replace("<span itemprop=\"genre\">", "").replace("</span>", "");
  429.                     g1 = genres[j].indexOf("\">") + 2;
  430.                     g2 = genres[j].indexOf("</a>");
  431.                     if(g2 == -1) { genres = null; break; }
  432.                     genres[j] = genres[j].substring(g1, g2).replace(/^\s+|\s+$/g, "").replace(/,/g, "");
  433.                    
  434.                     for(k = 0; k < tagsLength; k++)
  435.                     {
  436.                         if(tags[k].length == 0 || tags[k].toUpperCase() == genres[j].toUpperCase())
  437.                         {
  438.                             tags.splice(k, 1);
  439.                             tagsLength--;
  440.                             k--;
  441.                         }
  442.                     }
  443.                 }
  444.             }
  445.            
  446.             /* rank */
  447.             rankHtmlStartIndex = str.indexOf(RANK_START);
  448.             if(rankHtmlStartIndex != -1)
  449.             {
  450.                 rankHtmlStartIndex += RANK_START.length;
  451.                 rankHtmlEndIndex = str.indexOf("<sup>", rankHtmlStartIndex);
  452.                 rankHtml = str.substring(rankHtmlStartIndex, rankHtmlEndIndex);
  453.                 rankHtml = rankHtml.replace(/^\s+|\s+$/g, "").replace("#", "");
  454.             }
  455.            
  456.             /* score */
  457.             scoreHtml = "";
  458.             scoreEle = $(doc).find(SCORE_SELECTOR);
  459.             if(scoreEle.length > 0)
  460.             {
  461.                 scoreHtml = scoreEle.text().trim();
  462.             }
  463.  
  464.             if(chkTags.checked)
  465.             {
  466.                 if(englishHtml && chkEnglish.checked) { tags.push(englishHtml); }
  467.                 if(season && chkSeason.checked) { tags.push(season); }
  468.                 if(year && chkYear.checked) { tags.push(year); }
  469.                 if(studios && chkStudio.checked) { tags = tags.concat(studios); }
  470.                 if(producers && chkProducers.checked) { tags = tags.concat(producers); }
  471.                 if(genres && chkGenres.checked) { tags = tags.concat(genres); }
  472.                 if(chkAired.checked) { tags.push("Aired: " + dateArr[0].replace(/^\s+|\s+$/g, "") + (dateArr.length == 2 ? " to " + dateArr[1].replace(/^\s+|\s+$/g, "") : "")); }
  473.                 if(chkScore.checked) { tags.push("Score: " + scoreHtml); }
  474.                 if(chkRank.checked) { tags.push("Ranked: " + rankHtml); }
  475.                
  476.                 newTagStr = tags.join(", ");
  477.                
  478.                 request2 = new XMLHttpRequest();
  479.                 request2.open("post", "https://myanimelist.net/includes/ajax.inc.php?t=22&tags=" + encodeURIComponent(newTagStr), false);
  480.                 request2.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
  481.                 request2.setRequestHeader("X-Requested-With", "XMLHttpRequest");
  482.                 var csrf = $('meta[name="csrf_token"]').attr('content');
  483.                 request2.send("aid=" + id + "&csrf_token=" + csrf);
  484.             }
  485.            
  486.             /* thumbs */
  487.             img = $(doc).find("img[itemprop=\"image\"]")[0];
  488.             imgUrl = img.src;
  489.             imgUrlt = imgUrl.replace(".jpg", "t.jpg");
  490.             imgUrlv = imgUrl.replace(".jpg", "v.jpg");
  491.            
  492.             altText = img.alt;
  493.            
  494.             /* Synopsis (description) */
  495.             desc = $(doc).find("[itemprop=\"description\"]").text().replace(/\r\n/g, " ").replace(/\n/g, "\\a").replace(/\"/g, "\\\"").replace(/^\s+|\s+$/g, "");
  496.            
  497.             cssLine = template.value
  498.                 .replace(/\[DEL\]/g, "")
  499.                 .replace(/\[ID\]/g, id)
  500.                 .replace(/\[IMGURL\]/g, imgUrl)
  501.                 .replace(/\[IMGURLT\]/g, imgUrlt)
  502.                 .replace(/\[IMGURLV\]/g, imgUrlv)
  503.                 .replace(/\[TITLE\]/g, altText)
  504.                 .replace(/\[ENGTITLE\]/g, englishHtml ? englishHtml : altText)
  505.                 .replace(/\[GENRES\]/g, genres ? genres.join(", ") : "")
  506.                 .replace(/\[STUDIOS\]/g, studios ? studios.join(", ") : "")
  507.                 .replace(/\[PRODUCERS\]/g, producers ? producers.join(", ") : "")
  508.                 .replace(/\[SEASON\]/g, season)
  509.                 .replace(/\[YEAR\]/g, year)
  510.                 .replace(/\[RANK\]/g, rankHtml)
  511.                 .replace(/\[SCORE\]/g, scoreHtml)
  512.                 .replace(/\[STARTDATE\]/g, dateArr[0].replace(/^\s+|\s+$/g, ""))
  513.                 .replace(/\[ENDDATE\]/g, dateArr.length == 2 ? dateArr[1].replace(/^\s+|\s+$/g, "") : "")
  514.                 .replace(/\[DESC\]/g, desc);
  515.            
  516.             result.value += cssLine + "\n";
  517.         }
  518.         catch(e)
  519.         {
  520.             /*alert("error " + moreId + ":" + e);*/
  521.             console.log("error " + moreId, e);
  522.             errorCount++;
  523.         }
  524.        
  525.         i++;
  526.        
  527.         statusText.innerHTML = "Processed " + i + " of " + moreIds.length;
  528.        
  529.         setTimeout(ProcessNext, delay.value);
  530.     }
  531.     else
  532.     {
  533.         thumbBtn.value = "Done (close)";
  534.         thumbBtn.onclick = function()
  535.         {
  536.             document.body.removeChild(tempDiv);
  537.             if(chkTags.checked)
  538.             {
  539.                 alert("Refesh the page for tag updates to show.");
  540.             }
  541.             if(errorCount > 0)
  542.             {
  543.                 alert(errorCount + " errors occurred while processing.  See console for details.\n\n'Some' udpates were probably successful.\nYou may need to rerun the tool to catch the rest (with updated CSS as input and after refreshing your list page).");
  544.             }
  545.         };
  546.     }
  547. }
  548.  
  549. function Process()
  550. {
  551.     imageLoadDelay = 0;
  552.     exitBtn.disabled = "disabled";
  553.     thumbBtn.value = "Stop";
  554.     thumbBtn.onclick = function(){ moreIds = new Array();};
  555.    
  556.     result.value += "\/* Generated by MAL List Tool http://burntjello.webs.com\nTemplate=" + template.value.replace(/\*\//g, "*[DEL]/") + "\nMatchTemplate=" + matchTemplate.value + "\n*\/\n";
  557.    
  558.     if(modernStyle) { ids = $("tr.more-info").map(function () { return this.id.replace("more-", ""); } ).get() ; } else { ids = $("div.hide").map(function () { return this.id.replace("more", ""); } ).get() ; }
  559.    
  560.     idsLength = ids.length;
  561.     for(k = 0; k < idsLength; k++)
  562.     {
  563.         indexOf = -1;
  564.         oldLines = existing.value.split("\n");
  565.         oldLinesCount = oldLines.length;
  566.         for(j = 0; j < oldLinesCount; j++)
  567.         {
  568.             oldId = matchTemplate.value.replace(/\[ID\]/g, ids[k]);
  569.             indexOf = oldLines[j].indexOf(oldId);
  570.             if(indexOf != -1)
  571.             {
  572.                 break;
  573.             }
  574.         }
  575.  
  576.         if(indexOf != -1)
  577.         {
  578.             if(chkExisting.checked)
  579.             {
  580.                 imageLoadDelay = 5000;
  581.                 urlStart = oldLines[j].indexOf("http");
  582.                 urlEnd = oldLines[j].indexOf(".jpg", urlStart);
  583.                 imgUrl = oldLines[j].substring(urlStart, urlEnd + 4);
  584.                 tempImg = document.createElement("img");
  585.                 tempImg.oldLine = oldLines[j];
  586.                 tempImg.animeId = ids[k];
  587.                 tempImg.onload = function(imgLoadEvent)
  588.                 {
  589.                     /*console.log("imgLoadEvent(" + imgUrl + ")", imgLoadEvent.target.naturalHeight);*/
  590.                     result.value += imgLoadEvent.target.oldLine + "\n";
  591.                 };
  592.                 tempImg.onerror = function(imgErrorEvent)
  593.                 {
  594.                     /*console.log("imgErrorEvent(" + imgUrl + ")", imgErrorEvent);*/
  595.                     moreIds.push(imgErrorEvent.target.animeId);
  596.                 };
  597.                 tempImg.src = imgUrl;
  598.             }
  599.             else
  600.             {
  601.                 result.value += oldLines[j] + "\n";
  602.             }
  603.         }
  604.         else
  605.         {
  606.             moreIds.push(ids[k]);
  607.         }
  608.     }
  609.  
  610.     setTimeout(ProcessNext, imageLoadDelay);
  611. }
  612.  
  613. thumbBtn.onclick = function() { Process(); };
  614. exitBtn.onclick = function() { document.body.removeChild(tempDiv); };
  615.  
  616. function Start()
  617. {
  618.     alert("It's best to use 'All Anime' view.\n\nCopy existing styles to the textarea before starting.\n\nThis script will remove what is no longer needed, skip what already exists, and add the rest.\n\nThe input controls have tooltips, hover over them to see what they are for.");
  619. }
  620.  
  621. Start();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement