Advertisement
ValerioLyndon

MyAnimeList CSS Generator alt preset

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