Advertisement
Guest User

Mangaupdates Groups Fix - Feb 2019 (Full) - 3/1/19 Fix

a guest
Mar 1st, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.71 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Mangaupdates Groups Fix
  3. // @namespace Mangaupdates Groups Fix (https://github.com/loadletter/mangaupdates-urlfix)
  4. // @description Makes clickable links to scanlators websites
  5. // @match *://www.mangaupdates.com/groups.html*
  6. // @match *://www.mangaupdates.com/mylist.html*
  7. // @match *://www.mangaupdates.com/releases.html*
  8. // @version 1.8
  9. // @downloadURL https://github.com/loadletter/mangaupdates-urlfix/raw/master/mangaupdates_urlfix.user.js
  10. // @updateURL https://github.com/loadletter/mangaupdates-urlfix/raw/master/mangaupdates_urlfix.user.js
  11. // @grant none
  12. // February 2019 fixes by https://github.com/anon-programmer
  13. // February 2019 UI fixes by https://github.com/Hyacia
  14. // ==/UserScript==
  15.  
  16. if (window.location.pathname === "/mylist.html") {
  17. set_lastgroup();
  18. } else if (window.location.pathname === "/releases.html") {
  19. red_lastgroup();
  20. } else if ('id' in get_query_params()) {
  21. fix_irc();
  22. fix_url();
  23. update_groups();
  24. } else {
  25. set_redirection();
  26. }
  27.  
  28. function update_groups() {
  29. var urlfix_groups = document.createElement('script');
  30. var urlfix_groupshard = parseInt(document.URL.replace(/^.+id=/,'').replace('#', ''), 10) % 20;
  31. if (urlfix_groupshard !== urlfix_groupshard) {
  32. return;
  33. }
  34. urlfix_groups.type = "text/javascript";
  35. urlfix_groups.src = "//loadletter.github.io/mangaupdates-urlfix/src/groups/" + urlfix_groupshard + ".js";
  36. urlfix_groups.onreadystatechange = fix_url;
  37. urlfix_groups.onload = fix_url;
  38. urlfix_groups.onerror = fix_url; /* Why not */
  39. (document.body || document.head || document.documentElement).appendChild(urlfix_groups);
  40. }
  41.  
  42. function fix_url() {
  43. var oscript = document.createElement('script');
  44. oscript.appendChild(document.createTextNode('('+ insertScript +')();'));
  45. (document.body || document.head || document.documentElement).appendChild(oscript);
  46. }
  47.  
  48. function fix_irc() {
  49. var list = document.getElementsByClassName("text");
  50. var irc='';
  51. for (var i=0; i<list.length; i++) {
  52. if(list[i].innerHTML == "<u>IRC</u>") {
  53. list[i].id = "fixed_irc_url";
  54. if((irc=list[i].nextElementSibling.innerHTML) != "<i>No IRC</i>") {
  55. var a = irc.replace(/^.+@/,'');
  56. var b = irc.replace('#','').replace(/@.*/,'');
  57. list[++i].innerHTML='<a href="irc://'+a+'/'+b+'"><u>'+a+'/'+b+'</u></a>';
  58. }
  59. }
  60. }
  61. }
  62.  
  63. function get_query_params() {
  64. var match, urlParams,
  65. pl = /\+/g,
  66. search = /([^&=]+)=?([^&]*)/g,
  67. decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
  68. query = window.location.search.substring(1);
  69.  
  70. urlParams = {};
  71. while (match = search.exec(query))
  72. urlParams[decode(match[1])] = decode(match[2]);
  73.  
  74. return urlParams;
  75. }
  76.  
  77. function set_redirection() {
  78. var prev_el = document.querySelector('a[href="groups.html?active=false"]');
  79. if (!prev_el) {
  80. return;
  81. }
  82. var toggle_el = document.createElement('a');
  83. var redir_key = 'loadletter.urlfix.settings.redirect';
  84. var toggle_text = function () {
  85. toggle_el.innerHTML = (typeof(localStorage) !== "undefined" && localStorage.getItem(redir_key)) ? '<u>Do not redirect to website</u>' : '<u>Redirect to group website</u>';
  86. };
  87. toggle_text();
  88. toggle_el.title = "Toggle redirection of mangaupdates group entries to their respective website";
  89. toggle_el.onclick = function () {
  90. if (typeof(localStorage) === "undefined") {
  91. alert("Couldn't save setting, your browser does not support HTML5 localStorage");
  92. return;
  93. }
  94. if (localStorage.getItem(redir_key)) {
  95. localStorage.removeItem(redir_key);
  96. } else {
  97. localStorage.setItem(redir_key, "true");
  98. }
  99. toggle_text();
  100. };
  101. var parent_el = prev_el.parentElement;
  102. parent_el.innerHTML = parent_el.innerHTML.replace(/\s+$/, '') + '&nbsp;&nbsp;';
  103. parent_el.appendChild(toggle_el);
  104. }
  105.  
  106. function set_lastgroup () {
  107. var prev_el = document.querySelector('div.low_col1 > a');
  108. if (!prev_el) {
  109. return;
  110. }
  111. var text_el = document.createTextNode(']\u00a0[');
  112. var toggle_el = document.createElement('a');
  113. var redir_key = 'loadletter.urlfix.settings.lastgroup';
  114. var toggle_text = function () {
  115. var toggle_hrefs = function (toggled) {
  116. var latest_chapter = document.querySelectorAll('#list_table span.newlist > a');
  117. for (var i=0; i<latest_chapter.length; i++) {
  118. var hr = latest_chapter[i].href.split('#')[0];
  119. latest_chapter[i].href = toggled ? (hr + '#showLastScanlator') : hr;
  120. }
  121. };
  122. if (typeof(localStorage) !== "undefined" && localStorage.getItem(redir_key)) {
  123. toggle_hrefs(true);
  124. toggle_el.innerHTML = '<u>Show all scanlations</u>';
  125. } else {
  126. toggle_hrefs(false);
  127. toggle_el.innerHTML = '<u>Jump to latest scanlation</u>';
  128. }
  129. };
  130. toggle_text();
  131. toggle_el.title = "Toggles redirection to the scanlator of the last chapter when clicking the link next to the series name";
  132. toggle_el.onclick = function () {
  133. if (typeof(localStorage) === "undefined") {
  134. alert("Couldn't save setting, your browser does not support HTML5 localStorage");
  135. return;
  136. }
  137. if (localStorage.getItem(redir_key)) {
  138. localStorage.removeItem(redir_key);
  139. } else {
  140. localStorage.setItem(redir_key, "true");
  141. }
  142. toggle_text();
  143. };
  144. prev_el.parentNode.insertBefore(text_el, prev_el.nextSibling);
  145. text_el.parentNode.insertBefore(toggle_el, text_el.nextSibling);
  146. }
  147.  
  148. function red_lastgroup () {
  149. if (!('search' in get_query_params() && window.location.hash === '#showLastScanlator')) {
  150. return;
  151. }
  152. var latest_group = document.querySelector('#main_content a[title="Group Info"][href*="groups.html"]');
  153. if (latest_group) {
  154. window.location.href = latest_group.href;
  155. }
  156. }
  157.  
  158. /* all the stuff related to the website thing has been moved here,
  159. * since the groups variable can't be accessed from the usescript */
  160. function insertScript() {
  161. window.urlfix_groupID = parseInt(document.URL.replace(/^.+id=/,'').replace('#', ''), 10);
  162. if (window.urlfix_groupID !== window.urlfix_groupID) {
  163. return;
  164. }
  165. var urlfix_local;
  166. var urlfix_local_name = "loadletter.urlfix.groups." + (window.urlfix_groupID % 20);
  167. if(typeof(window.urlfix_grouplist) !== "undefined") {
  168. window.urlfix_groupSite = window.urlfix_grouplist[String(window.urlfix_groupID)];
  169. if(typeof(localStorage) !== "undefined") {
  170. localStorage.setItem(urlfix_local_name, JSON.stringify(window.urlfix_grouplist));
  171. if (window.urlfix_groupSite !== undefined && localStorage.getItem('loadletter.urlfix.settings.redirect') && /^https?:\/\//.test(window.urlfix_groupSite)) {
  172. window.location.href = window.urlfix_groupSite;
  173. }
  174. }
  175. } else {
  176. if(typeof(localStorage) !== "undefined" && (urlfix_local = localStorage.getItem(urlfix_local_name))) {
  177. window.urlfix_groupSite = JSON.parse(urlfix_local)[window.urlfix_groupID];
  178. if (window.urlfix_groupSite !== undefined && localStorage.getItem('loadletter.urlfix.settings.redirect') && /^https?:\/\//.test(window.urlfix_groupSite)) {
  179. window.location.href = window.urlfix_groupSite;
  180. }
  181. } else {
  182. window.urlfix_groupSite = undefined;
  183. }
  184. }
  185. window.urlfix_openSuggBox = function() {
  186. if(typeof(urlfix_grouplist_shard) === "undefined")
  187. alert("Could not fetch latest info, the website might be outdated, consider refreshing the page before submitting a new entry");
  188. var suggboxurl = "http://mufix.herokuapp.com/form?group=" + urlfix_groupID;
  189. if(urlfix_groupSite !== "undefined")
  190. suggboxurl += "&update=yes";
  191. window.open(suggboxurl, '', 'scrollbars=no,resizable=yes, width=700,height=200,status=no,location=no,toolbar=no');
  192. };
  193. var urlfix_site_fixed = document.getElementById('fixed_group_suggestion');
  194. var urlfix_site = urlfix_site_fixed || document.createElement('div');
  195. urlfix_site.setAttribute("class", "p-1 col-6 text");
  196. urlfix_site.id = "fixed_group_suggestion";
  197. urlfix_site.innerHTML = '<u>Site</u><a href="#" onclick="urlfix_openSuggBox();"> (Suggest an update)</a>';
  198. var urlfix_site_par = document.querySelector('div.general_table:nth-child(1) > div:nth-child(2) > div:nth-child(1) > div:nth-child(1) > div:nth-child(5)');
  199. urlfix_site_par.parentNode.insertBefore(urlfix_site, urlfix_site_par);
  200. if(!urlfix_site_fixed) {
  201. var urlfix_irc_par = document.getElementById("fixed_irc_url").parentNode;
  202. urlfix_irc_par.parentNode.insertAfter(urlfix_site, urlfix_irc_par.nextSibling);
  203. }
  204. var site_link_fixed = document.getElementById('fixed_site_link');
  205. var site_link = site_link_fixed || document.createElement('div');
  206. site_link.setAttribute("class", "p-1 col-6 text");
  207. site_link.id = "fixed_site_link";
  208. site_link.innerHTML = (urlfix_groupSite === undefined ? '<i>No Info</i>' : ('<a target="_blank" alt="" href="' + urlfix_groupSite + '"><u>' + urlfix_groupSite + '</u></a>'));
  209. var site_link_par = document.querySelector('#fixed_group_suggestion');
  210. site_link_par.parentNode.insertBefore(site_link, urlfix_site);
  211. if(!site_link_fixed) {
  212. var site_link_par = document.getElementById("fixed_site_link");
  213. site_link_par.parentNode.insertBefore(site_link, urlfix_site_par.nextSibling);
  214. }
  215. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement