Advertisement
ValerioLyndon

BurntJello Bookmarklet temp

Mar 8th, 2021
750
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 = '.progress-[ID]:after{content:"[SCORE]";}';
  9. MATCH_TEMPLATE = ".progress-[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.                 englishUpper = englishHtml.toUpperCase();
  256.                 for(k = 0; k < tagsLength; k++)
  257.                 {
  258.                     if(tags[k].length == 0 || tags[k].toUpperCase() == englishUpper)
  259.                     {
  260.                         tags.splice(k, 1);
  261.                         tagsLength--;
  262.                         k--;
  263.                     }
  264.                 }
  265.             }
  266.            
  267.             /* synonyms */
  268.             if(englishHtml == null)
  269.             {
  270.                 synHtmlStartIndex = str.indexOf(SYN_START);
  271.                 if(str.indexOf(SYN_START) != -1)
  272.                 {
  273.                     synHtmlStartIndex += SYN_START.length;
  274.                     synHtmlEndIndex = str.indexOf("</div>", synHtmlStartIndex);
  275.                     synHtml = str.substring(synHtmlStartIndex, synHtmlEndIndex);
  276.                     synArr = synHtml.split(",");
  277.                     if(synArr.length > 0)
  278.                     {
  279.                         englishHtml = synArr[0].replace(/^\s+|\s+$/g, "");
  280.                         synUpper = englishHtml.toUpperCase();
  281.                         for(k = 0; k < tagsLength; k++)
  282.                         {
  283.                             if(tags[k].length == 0 || tags[k].toUpperCase() == synUpper)
  284.                             {
  285.                                 tags.splice(k, 1);
  286.                                 tagsLength--;
  287.                                 k--;
  288.                             }
  289.                         }
  290.                     }
  291.                 }
  292.             }
  293.            
  294.             /* date */
  295.             season = null;
  296.             year = null;
  297.             DATE_START = ( animeManga == "anime" ) ? AIRED_START : PUBLISHED_START;
  298.             dateHtmlStartIndex = str.indexOf(DATE_START) + DATE_START.length;
  299.             if(str.indexOf(DATE_START) != -1)
  300.             {
  301.                 dateHtmlEndIndex = str.indexOf("</div>", dateHtmlStartIndex);
  302.                 dateHtml = str.substring(dateHtmlStartIndex, dateHtmlEndIndex);
  303.                 dateArr = dateHtml.split(" to ");
  304.                 date1Arr = dateArr[0].split(",");
  305.                 if(date1Arr.length == 2)
  306.                 {
  307.                     season = null;
  308.                     if(date1Arr[0].indexOf("Jan") != -1 || date1Arr[0].indexOf("Feb") != -1 || date1Arr[0].indexOf("Mar") != -1)
  309.                     {
  310.                         season = "Winter";
  311.                     }
  312.                     if(date1Arr[0].indexOf("Apr") != -1 || date1Arr[0].indexOf("May") != -1 || date1Arr[0].indexOf("Jun") != -1)
  313.                     {
  314.                         season = "Spring";
  315.                     }
  316.                     if(date1Arr[0].indexOf("Jul") != -1 || date1Arr[0].indexOf("Aug") != -1 || date1Arr[0].indexOf("Sep") != -1)
  317.                     {
  318.                         season = "Summer";
  319.                     }
  320.                     if(date1Arr[0].indexOf("Oct") != -1 || date1Arr[0].indexOf("Nov") != -1 || date1Arr[0].indexOf("Dec") != -1)
  321.                     {
  322.                         season = "Fall";
  323.                     }
  324.                     year = date1Arr[1].replace(/^\s+|\s+$/g, "");
  325.                     for(k = 0; k < tagsLength; k++)
  326.                     {
  327.                         if(tags[k].length == 0 || tags[k].toUpperCase() == season.toUpperCase() || tags[k] == year)
  328.                         {
  329.                             tags.splice(k, 1);
  330.                             tagsLength--;
  331.                             k--;
  332.                         }
  333.                     }
  334.                 }
  335.             }
  336.            
  337.             /* studio (anime) */
  338.             studios = null;
  339.             studiosHtmlStartIndex = str.indexOf(STUDIOS_START);
  340.             if(str.indexOf(STUDIOS_START) != -1)
  341.             {
  342.                 studiosHtmlStartIndex += STUDIOS_START.length;
  343.                 studiosHtmlEndIndex = str.indexOf("</div>", studiosHtmlStartIndex);
  344.                 studiosHtml = str.substring(studiosHtmlStartIndex, studiosHtmlEndIndex);
  345.                
  346.                 studios = studiosHtml.split(",");
  347.                 studiosLength = studios.length;
  348.                 for(j = 0; j < studiosLength; j++)
  349.                 {
  350.                     g1 = studios[j].indexOf("\">") + 2;
  351.                     g2 = studios[j].indexOf("</a>");
  352.                     if(g2 == -1) { studios = null; break; }
  353.                     studios[j] = studios[j].substring(g1, g2).replace(/^\s+|\s+$/g, "");
  354.                     studioUpper = studios[j].toUpperCase();
  355.                    
  356.                     for(k = 0; k < tagsLength; k++)
  357.                     {
  358.                         if(tags[k].length == 0 || tags[k].toUpperCase() == studioUpper)
  359.                         {
  360.                             tags.splice(k, 1);
  361.                             tagsLength--;
  362.                             k--;
  363.                         }
  364.                     }
  365.                 }
  366.             }
  367.            
  368.             /* producers (anime) */
  369.             producers = null;
  370.             producersHtmlStartIndex = str.indexOf(PRODUCERS_START);
  371.             if(str.indexOf(PRODUCERS_START) != -1)
  372.             {
  373.                 producersHtmlStartIndex += PRODUCERS_START.length;
  374.                 producersHtmlEndIndex = str.indexOf("</div>", producersHtmlStartIndex);
  375.                 producersHtml = str.substring(producersHtmlStartIndex, producersHtmlEndIndex);
  376.    
  377.                 producers = producersHtml.split(",");
  378.                 producersLength = producers.length;
  379.                 for(j = 0; j < producersLength; j++)
  380.                 {
  381.                     if(producers[j].indexOf("<sup>") == -1)
  382.                     {
  383.                         g1 = producers[j].indexOf("\">") + 2;
  384.                         g2 = producers[j].indexOf("</a>");
  385.                         if(g2 == -1) { producers = null; break; }
  386.                         producers[j] = producers[j].substring(g1, g2).replace(/^\s+|\s+$/g, "");
  387.                         studioUpper = producers[j].toUpperCase();
  388.                        
  389.                         for(k = 0; k < tagsLength; k++)
  390.                         {
  391.                             if(tags[k].length == 0 || tags[k].toUpperCase() == studioUpper)
  392.                             {
  393.                                 tags.splice(k, 1);
  394.                                 tagsLength--;
  395.                                 k--;
  396.                             }
  397.                         }
  398.                     }
  399.                     else
  400.                     {
  401.                         producers.splice(j, 1);
  402.                         producersLength--;
  403.                         j--;
  404.                     }
  405.                 }
  406.             }
  407.            
  408.             /* genres */
  409.             genres = null;
  410.             genresHtmlStartIndex = str.indexOf(GENRES_START);
  411.             if(str.indexOf(GENRES_START) != -1)
  412.             {
  413.                 genresHtmlStartIndex += RANK_START.length;
  414.                 genresHtmlEndIndex = str.indexOf("</div>", genresHtmlStartIndex);
  415.                 genresHtml = str.substring(genresHtmlStartIndex, genresHtmlEndIndex);
  416.                
  417.                 genres = genresHtml.split(",");
  418.                 genresLength = genres.length;
  419.                 for(j = 0; j < genresLength; j++)
  420.                 {
  421.                     genres[j] = genres[j].replace("<span itemprop=\"genre\">", "").replace("</span>", "");
  422.                     g1 = genres[j].indexOf("\">") + 2;
  423.                     g2 = genres[j].indexOf("</a>");
  424.                     if(g2 == -1) { genres = null; break; }
  425.                     genres[j] = genres[j].substring(g1, g2).replace(/^\s+|\s+$/g, "").replace(/,/g, "");
  426.                    
  427.                     for(k = 0; k < tagsLength; k++)
  428.                     {
  429.                         if(tags[k].length == 0 || tags[k].toUpperCase() == genres[j].toUpperCase())
  430.                         {
  431.                             tags.splice(k, 1);
  432.                             tagsLength--;
  433.                             k--;
  434.                         }
  435.                     }
  436.                 }
  437.             }
  438.            
  439.             /* rank */
  440.             rankHtmlStartIndex = str.indexOf(RANK_START);
  441.             if(rankHtmlStartIndex != -1)
  442.             {
  443.                 rankHtmlStartIndex += RANK_START.length;
  444.                 rankHtmlEndIndex = str.indexOf("<sup>", rankHtmlStartIndex);
  445.                 rankHtml = str.substring(rankHtmlStartIndex, rankHtmlEndIndex);
  446.                 rankHtml = rankHtml.replace(/^\s+|\s+$/g, "").replace("#", "");
  447.             }
  448.            
  449.             /* score */
  450.             scoreHtml = "";
  451.             scoreEle = $(doc).find(SCORE_SELECTOR);
  452.             if(scoreEle.length > 0)
  453.             {
  454.                 scoreHtml = scoreEle.text().trim();
  455.             }
  456.  
  457.             if(chkTags.checked)
  458.             {
  459.                 if(englishHtml && chkEnglish.checked) { tags.push(englishHtml); }
  460.                 if(season && chkSeason.checked) { tags.push(season); }
  461.                 if(year && chkYear.checked) { tags.push(year); }
  462.                 if(studios && chkStudio.checked) { tags = tags.concat(studios); }
  463.                 if(producers && chkProducers.checked) { tags = tags.concat(producers); }
  464.                 if(genres && chkGenres.checked) { tags = tags.concat(genres); }
  465.                 if(chkAired.checked) { tags.push("Aired: " + dateArr[0].replace(/^\s+|\s+$/g, "") + (dateArr.length == 2 ? " to " + dateArr[1].replace(/^\s+|\s+$/g, "") : "")); }
  466.                 if(chkScore.checked) { tags.push("Score: " + scoreHtml); }
  467.                 if(chkRank.checked) { tags.push("Ranked: " + rankHtml); }
  468.                
  469.                 newTagStr = tags.join(", ");
  470.                
  471.                 request2 = new XMLHttpRequest();
  472.                 request2.open("post", "https://myanimelist.net/includes/ajax.inc.php?t=22&tags=" + encodeURIComponent(newTagStr), false);
  473.                 request2.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
  474.                 request2.setRequestHeader("X-Requested-With", "XMLHttpRequest");
  475.                 var csrf = $('meta[name="csrf_token"]').attr('content');
  476.                 request2.send("aid=" + id + "&csrf_token=" + csrf);
  477.             }
  478.            
  479.             /* thumbs */
  480.             img = $(doc).find("img[itemprop=\"image\"]")[0];
  481.             imgUrl = img.src;
  482.             imgUrlt = imgUrl.replace(".jpg", "t.jpg");
  483.             imgUrlv = imgUrl.replace(".jpg", "v.jpg");
  484.            
  485.             altText = img.alt;
  486.            
  487.             /* Synopsis (description) */
  488.             desc = $(doc).find("[itemprop=\"description\"]").text().replace(/\r\n/g, " ").replace(/\n/g, "\\a").replace(/\"/g, "\\\"").replace(/^\s+|\s+$/g, "");
  489.            
  490.             cssLine = template.value
  491.                 .replace(/\[DEL\]/g, "")
  492.                 .replace(/\[ID\]/g, id)
  493.                 .replace(/\[IMGURL\]/g, imgUrl)
  494.                 .replace(/\[IMGURLT\]/g, imgUrlt)
  495.                 .replace(/\[IMGURLV\]/g, imgUrlv)
  496.                 .replace(/\[TITLE\]/g, altText)
  497.                 .replace(/\[ENGTITLE\]/g, englishHtml ? englishHtml : altText)
  498.                 .replace(/\[GENRES\]/g, genres ? genres.join(", ") : "")
  499.                 .replace(/\[STUDIOS\]/g, studios ? studios.join(", ") : "")
  500.                 .replace(/\[PRODUCERS\]/g, producers ? producers.join(", ") : "")
  501.                 .replace(/\[SEASON\]/g, season)
  502.                 .replace(/\[YEAR\]/g, year)
  503.                 .replace(/\[RANK\]/g, rankHtml)
  504.                 .replace(/\[SCORE\]/g, scoreHtml)
  505.                 .replace(/\[STARTDATE\]/g, dateArr[0].replace(/^\s+|\s+$/g, ""))
  506.                 .replace(/\[ENDDATE\]/g, dateArr.length == 2 ? dateArr[1].replace(/^\s+|\s+$/g, "") : "")
  507.                 .replace(/\[DESC\]/g, desc);
  508.            
  509.             result.value += cssLine + "\n";
  510.         }
  511.         catch(e)
  512.         {
  513.             /*alert("error " + moreId + ":" + e);*/
  514.             console.log("error " + moreId, e);
  515.             errorCount++;
  516.         }
  517.        
  518.         i++;
  519.        
  520.         statusText.innerHTML = "Processed " + i + " of " + moreIds.length;
  521.        
  522.         setTimeout(ProcessNext, delay.value);
  523.     }
  524.     else
  525.     {
  526.         thumbBtn.value = "Done (close)";
  527.         thumbBtn.onclick = function()
  528.         {
  529.             document.body.removeChild(tempDiv);
  530.             if(chkTags.checked)
  531.             {
  532.                 alert("Refesh the page for tag updates to show.");
  533.             }
  534.             if(errorCount > 0)
  535.             {
  536.                 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).");
  537.             }
  538.         };
  539.     }
  540. }
  541.  
  542. function Process()
  543. {
  544.     imageLoadDelay = 0;
  545.     exitBtn.disabled = "disabled";
  546.     thumbBtn.value = "Stop";
  547.     thumbBtn.onclick = function(){ moreIds = new Array();};
  548.    
  549.     result.value += "\/* Generated by MAL List Tool http://burntjello.webs.com\nTemplate=" + template.value.replace(/\*\//g, "*[DEL]/") + "\nMatchTemplate=" + matchTemplate.value + "\n*\/\n";
  550.    
  551.     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() ; }
  552.    
  553.     idsLength = ids.length;
  554.     for(k = 0; k < idsLength; k++)
  555.     {
  556.         indexOf = -1;
  557.         oldLines = existing.value.split("\n");
  558.         oldLinesCount = oldLines.length;
  559.         for(j = 0; j < oldLinesCount; j++)
  560.         {
  561.             oldId = matchTemplate.value.replace(/\[ID\]/g, ids[k]);
  562.             indexOf = oldLines[j].indexOf(oldId);
  563.             if(indexOf != -1)
  564.             {
  565.                 break;
  566.             }
  567.         }
  568.  
  569.         if(indexOf != -1)
  570.         {
  571.             if(chkExisting.checked)
  572.             {
  573.                 imageLoadDelay = 5000;
  574.                 urlStart = oldLines[j].indexOf("http");
  575.                 urlEnd = oldLines[j].indexOf(".jpg", urlStart);
  576.                 imgUrl = oldLines[j].substring(urlStart, urlEnd + 4);
  577.                 tempImg = document.createElement("img");
  578.                 tempImg.oldLine = oldLines[j];
  579.                 tempImg.animeId = ids[k];
  580.                 tempImg.onload = function(imgLoadEvent)
  581.                 {
  582.                     /*console.log("imgLoadEvent(" + imgUrl + ")", imgLoadEvent.target.naturalHeight);*/
  583.                     result.value += imgLoadEvent.target.oldLine + "\n";
  584.                 };
  585.                 tempImg.onerror = function(imgErrorEvent)
  586.                 {
  587.                     /*console.log("imgErrorEvent(" + imgUrl + ")", imgErrorEvent);*/
  588.                     moreIds.push(imgErrorEvent.target.animeId);
  589.                 };
  590.                 tempImg.src = imgUrl;
  591.             }
  592.             else
  593.             {
  594.                 result.value += oldLines[j] + "\n";
  595.             }
  596.         }
  597.         else
  598.         {
  599.             moreIds.push(ids[k]);
  600.         }
  601.     }
  602.  
  603.     setTimeout(ProcessNext, imageLoadDelay);
  604. }
  605.  
  606. thumbBtn.onclick = function() { Process(); };
  607. exitBtn.onclick = function() { document.body.removeChild(tempDiv); };
  608.  
  609. function Start()
  610. {
  611.     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.");
  612. }
  613.  
  614. Start();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement