Advertisement
Guest User

Mangaupdates Groups Fix - Feb 2019 (Full)

a guest
Mar 1st, 2019
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.73 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.innerText) != "<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. break;
  60. }
  61. }
  62. }
  63.  
  64. function get_query_params() {
  65. var match, urlParams,
  66. pl = /\+/g,
  67. search = /([^&=]+)=?([^&]*)/g,
  68. decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
  69. query = window.location.search.substring(1);
  70.  
  71. urlParams = {};
  72. while (match = search.exec(query))
  73. urlParams[decode(match[1])] = decode(match[2]);
  74.  
  75. return urlParams;
  76. }
  77.  
  78. function set_redirection() {
  79. var prev_el = document.querySelector('a[href="groups.html?active=false"]');
  80. if (!prev_el) {
  81. return;
  82. }
  83. var toggle_el = document.createElement('a');
  84. var redir_key = 'loadletter.urlfix.settings.redirect';
  85. var toggle_text = function () {
  86. toggle_el.innerHTML = (typeof(localStorage) !== "undefined" && localStorage.getItem(redir_key)) ? '<u>Do not redirect to website</u>' : '<u>Redirect to group website</u>';
  87. };
  88. toggle_text();
  89. toggle_el.title = "Toggle redirection of mangaupdates group entries to their respective website";
  90. toggle_el.onclick = function () {
  91. if (typeof(localStorage) === "undefined") {
  92. alert("Couldn't save setting, your browser does not support HTML5 localStorage");
  93. return;
  94. }
  95. if (localStorage.getItem(redir_key)) {
  96. localStorage.removeItem(redir_key);
  97. } else {
  98. localStorage.setItem(redir_key, "true");
  99. }
  100. toggle_text();
  101. };
  102. var parent_el = prev_el.parentElement;
  103. parent_el.innerHTML = parent_el.innerHTML.replace(/\s+$/, '') + '&nbsp;&nbsp;';
  104. parent_el.appendChild(toggle_el);
  105. }
  106.  
  107. function set_lastgroup () {
  108. var prev_el = document.querySelector('div.low_col1 > a');
  109. if (!prev_el) {
  110. return;
  111. }
  112. var text_el = document.createTextNode(']\u00a0[');
  113. var toggle_el = document.createElement('a');
  114. var redir_key = 'loadletter.urlfix.settings.lastgroup';
  115. var toggle_text = function () {
  116. var toggle_hrefs = function (toggled) {
  117. var latest_chapter = document.querySelectorAll('#list_table span.newlist > a');
  118. for (var i=0; i<latest_chapter.length; i++) {
  119. var hr = latest_chapter[i].href.split('#')[0];
  120. latest_chapter[i].href = toggled ? (hr + '#showLastScanlator') : hr;
  121. }
  122. };
  123. if (typeof(localStorage) !== "undefined" && localStorage.getItem(redir_key)) {
  124. toggle_hrefs(true);
  125. toggle_el.innerHTML = '<u>Show all scanlations</u>';
  126. } else {
  127. toggle_hrefs(false);
  128. toggle_el.innerHTML = '<u>Jump to latest scanlation</u>';
  129. }
  130. };
  131. toggle_text();
  132. toggle_el.title = "Toggles redirection to the scanlator of the last chapter when clicking the link next to the series name";
  133. toggle_el.onclick = function () {
  134. if (typeof(localStorage) === "undefined") {
  135. alert("Couldn't save setting, your browser does not support HTML5 localStorage");
  136. return;
  137. }
  138. if (localStorage.getItem(redir_key)) {
  139. localStorage.removeItem(redir_key);
  140. } else {
  141. localStorage.setItem(redir_key, "true");
  142. }
  143. toggle_text();
  144. };
  145. prev_el.parentNode.insertBefore(text_el, prev_el.nextSibling);
  146. text_el.parentNode.insertBefore(toggle_el, text_el.nextSibling);
  147. }
  148.  
  149. function red_lastgroup () {
  150. if (!('search' in get_query_params() && window.location.hash === '#showLastScanlator')) {
  151. return;
  152. }
  153. var latest_group = document.querySelector('#main_content a[title="Group Info"][href*="groups.html"]');
  154. if (latest_group) {
  155. window.location.href = latest_group.href;
  156. }
  157. }
  158.  
  159. /* all the stuff related to the website thing has been moved here,
  160. * since the groups variable can't be accessed from the usescript */
  161. function insertScript() {
  162. window.urlfix_groupID = parseInt(document.URL.replace(/^.+id=/,'').replace('#', ''), 10);
  163. if (window.urlfix_groupID !== window.urlfix_groupID) {
  164. return;
  165. }
  166. var urlfix_local;
  167. var urlfix_local_name = "loadletter.urlfix.groups." + (window.urlfix_groupID % 20);
  168. if(typeof(window.urlfix_grouplist) !== "undefined") {
  169. window.urlfix_groupSite = window.urlfix_grouplist[String(window.urlfix_groupID)];
  170. if(typeof(localStorage) !== "undefined") {
  171. localStorage.setItem(urlfix_local_name, JSON.stringify(window.urlfix_grouplist));
  172. if (window.urlfix_groupSite !== undefined && localStorage.getItem('loadletter.urlfix.settings.redirect') && /^https?:\/\//.test(window.urlfix_groupSite)) {
  173. window.location.href = window.urlfix_groupSite;
  174. }
  175. }
  176. } else {
  177. if(typeof(localStorage) !== "undefined" && (urlfix_local = localStorage.getItem(urlfix_local_name))) {
  178. window.urlfix_groupSite = JSON.parse(urlfix_local)[window.urlfix_groupID];
  179. if (window.urlfix_groupSite !== undefined && localStorage.getItem('loadletter.urlfix.settings.redirect') && /^https?:\/\//.test(window.urlfix_groupSite)) {
  180. window.location.href = window.urlfix_groupSite;
  181. }
  182. } else {
  183. window.urlfix_groupSite = undefined;
  184. }
  185. }
  186. window.urlfix_openSuggBox = function() {
  187. if(typeof(urlfix_grouplist_shard) === "undefined")
  188. alert("Could not fetch latest info, the website might be outdated, consider refreshing the page before submitting a new entry");
  189. var suggboxurl = "http://mufix.herokuapp.com/form?group=" + urlfix_groupID;
  190. if(urlfix_groupSite !== "undefined")
  191. suggboxurl += "&update=yes";
  192. window.open(suggboxurl, '', 'scrollbars=no,resizable=yes, width=700,height=200,status=no,location=no,toolbar=no');
  193. };
  194. var urlfix_site_fixed = document.getElementById('fixed_group_suggestion');
  195. var urlfix_site = urlfix_site_fixed || document.createElement('div');
  196. urlfix_site.setAttribute("class", "p-1 col-6 text");
  197. urlfix_site.id = "fixed_group_suggestion";
  198. urlfix_site.innerHTML = '<u>Site</u><a href="#" onclick="urlfix_openSuggBox();"> (Suggest an update)</a>';
  199. 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)');
  200. urlfix_site_par.parentNode.insertBefore(urlfix_site, urlfix_site_par);
  201. if(!urlfix_site_fixed) {
  202. var urlfix_irc_par = document.getElementById("fixed_irc_url").parentNode;
  203. urlfix_irc_par.parentNode.insertAfter(urlfix_site, urlfix_irc_par.nextSibling);
  204. }
  205. var site_link_fixed = document.getElementById('fixed_site_link');
  206. var site_link = site_link_fixed || document.createElement('div');
  207. site_link.setAttribute("class", "p-1 col-6 text");
  208. site_link.id = "fixed_site_link";
  209. site_link.innerHTML = (urlfix_groupSite === undefined ? '<i>No Info</i>' : ('<a target="_blank" alt="" href="' + urlfix_groupSite + '"><u>' + urlfix_groupSite + '</u></a>'));
  210. var site_link_par = document.querySelector('#fixed_group_suggestion');
  211. site_link_par.parentNode.insertBefore(site_link, urlfix_site);
  212. if(!site_link_fixed) {
  213. var site_link_par = document.getElementById("fixed_site_link");
  214. site_link_par.parentNode.insertBefore(site_link, urlfix_site_par.nextSibling);
  215. }
  216. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement