fix Matryoshka div for BH bbcode beta

fix Matryoshka div

  1. // ==UserScript==
  2. // @name fix Matryoshka div for BH bbcode beta
  3. // @description fix Matryoshka div
  4. // @namespace baha_bbcode_div_fix
  5. // @author Covenant
  6. // @version 0.9
  7. // @license MIT
  8. // @homepage
  9. // @match https://home.gamer.com.tw/artwork.php?sn=*
  10. // @match https://webcache.googleusercontent.com/search?q=cache:https://home.gamer.com.tw/artwork.php*
  11. // @match https://web.archive.org/web/*/*home.gamer.com.tw/artwork.php?sn=*
  12. // @match https://guild.gamer.com.tw/about.php?gsn=*
  13. // @icon data:image/x-icon;base64,AAABAAIAICAAAAEACACoCAAAJgAAABAQAAABAAgAaAUAAM4IAAAoAAAAIAAAAEAAAAABAAgAAAAAAIAEAAAAAAAAAAAAAAABAAAAAAAA////APb29gDw8PAA4+PjAN3d3ADMzMwAxsbGALu7uwCysrIAqqqqAKOjowCZmZkAiIiIAHh4dgBvb28AZmZmAFhYWABSUlEASkpKAEFBQQAzMzMAJycoAAUFBQAAAAAAAgH+AFpNLABwaT8AkIAtAK6aLwCzokkAoJZjAMGzZQDPxpYA49y3AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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xcXFxcXFxcXFxcXFxcXFxcXFxcXCBASFxcXFxcXFxcXFxcXFxcXFxcXFxcXFxcXFxcXFxcIEBAXFxcXFxcXFxcXFxcXFxcXFxcXFxcXFxcXFxcXFwgQEAkXFxcXFxcXFxcEFxcXFxcXFxcXFxcXFxcXFxcXFxAQDBcXFxcXFxcXFwwXFxcXFxcXFxcXFxcXFxcXFxcXCA4QCBcXFxcXFwkOFxcXFxcXFxcXFxcXFxcXFxcXFxcXCA8SEAwXFwwODBcXFxcXFxcXFxcXFxcXFxcXFxcXFxcXCBISEw4MDwgXFxcXFxcXFxcXFxcXFxcXFxcXFxcXFxcXFw4QFxcXFxcXFxcXFxcXChEREQoXFxcJCQ4OEhIRERMXFw4QEQkXFxcXFxcXFxcXFxcKEREREREREwkXCQkJERAQCgoREBcXFxcXFxcXFxcXFxcXChcKFwoXFxcXFxcJChERERERDBcMCRcMEhcXFxcXFxcXFxcXFxcXFxcRFxcXCQoRERERDBMSEhEcFxcXFxcXFxcXFxcXFxcXFwoRCRcXAwoREREREBocFxcXFxcXFxcXFxcXCRECFxcXChMTEREREBERHBERCRcXFxcXFxcXFxcXFxcXChEJCQkREREREREREREcAgsPCRIXFxcXFxcXFxcXFxcXChERERERERERERERExwXFwwSCRIXFxcXFxcXFxcXFxcNERERERERERERERERHBcKEgoSFxcXFxcXFxcXFxcXChEREREREREREREREREUERcXFxcXFxcXFxcXFxcXCg0NERERERERERERERERDQ0cCBIXFxcXFxcXFwoKDRERERERERERERERERENDQ0cHBwdIRcXFwoTEhEQERESEhINDQ0NDQ0NDQ0NDQ0cHBwdFxcXFxcXFxcXFxcXFxchHBwcHBweHh4eHBwcHBwhFxcXFxcXFxcXFxcXFxchHBwcHBwcHBwcHBwcHCEXFxcXFxcXFxcXFx8fHhwcHBwcHBwcHBweHyEhFxcXFxcXFxcXFxcXFxcXFxcXFxcXFxcXFxcXFxcXFxcXFxcXFxcXFxcXFxcXFxf////////wf///w7///4////8f////H////j////4////+P////h/3//8f9///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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFxcXFxcXFxcGDAgIFxcXFxcXFxcXFxcEERcXFwgXFxcXFxcXFxcEEAUXFxcXFxcXFxcXFxcXCBAXFxcXFxcXFxcXFxcXFwgQFxcXFxcGFxcXFxcXFxcEEAwXFxcMFxcXFxcXFxcXFwgSDA8OBBcXFwwXFxcXFxcXCBAPFxcXBhcXCgwLDA0NDQoIEQ8IBQ0XFxcGFwkXFw0PDxEREwwXFxcXFxcXFwwKFw8RHBEJFxcXFxcXDAkXDxEREREXEgcSFxcXFxcMEREREREPFwgSFwYODRERERERDxwcHBwPFxcXFyEfHxwcHBwcICEXFxcXIRwcHBwcHCAhFxcXFxcXF/8P///+d////H////z////8+////Hf///4H//9/Hf//gAH//9YD///8g///8gj///gJ//8AA///wA///wB///8=
  14. // @grant GM_setValue
  15. // @grant GM_getValue
  16. // @grant GM_registerMenuCommand
  17. // @grant GM_setClipboard
  18. // @run-at document-end
  19. // @noframes
  20. // ==/UserScript==
  21. async function fn_clipboard_w(str){
  22. try{
  23. await navigator.clipboard.writeText(str);
  24. }catch(e){alert(e.message);}
  25. finally{}
  26. }
  27. function fn_url(url){
  28. let obj_url=new URL(url);
  29. let params=obj_url.searchParams;
  30. return [obj_url,params];
  31. }
  32. function fn_htmlToBBCode(html){//soyuka/6183947
  33. html = html.replace(/<pre(.*?)>(.*?)<\/pre>/gmi, "[code]$2[/code]");
  34. html = html.replace(/<h[1-7](.*?)>(.*?)<\/h[1-7]>/, "\n[h]$2[/h]\n");
  35. //paragraph handling:
  36. //- if a paragraph opens on the same line as another one closes, insert an extra blank line
  37. //- opening tag becomes two line breaks
  38. //- closing tags are just removed
  39. // html += html.replace(/<\/p><p/<\/p>\n<p/gi;
  40. // html += html.replace(/<p[^>]*>/\n\n/gi;
  41. // html += html.replace(/<\/p>//gi;
  42.  
  43. /*html = html.replace(/<br>/gi, "\n");//*/
  44. html = html.replace(/<textarea(.*?)>(.*?)<\/textarea>/gmi, "\[code]$2\[\/code]");
  45. html = html.replace(/<b>/gi, "[b]");
  46. html = html.replace(/<i>/gi, "[i]");
  47. html = html.replace(/<u>/gi, "[u]");
  48. html = html.replace(/<\/b>/gi, "[/b]");
  49. html = html.replace(/<\/i>/gi, "[/i]");
  50. html = html.replace(/<\/u>/gi, "[/u]");
  51. html = html.replace(/<em>/gi, "[b]");
  52. html = html.replace(/<\/em>/gi, "[/b]");
  53. html = html.replace(/<strong>/gi, "[b]");
  54. html = html.replace(/<\/strong>/gi, "[/b]");
  55. html = html.replace(/<cite>/gi, "[i]");
  56. html = html.replace(/<\/cite>/gi, "[/i]");
  57. html = html.replace(/<font color="(.*?)">(.*?)<\/font>/gmi, "[color=$1]$2[/color]");
  58. html = html.replace(/<font color=(.*?)>(.*?)<\/font>/gmi, "[color=$1]$2[/color]");
  59. html = html.replace(/<link(.*?)>/gi, "");
  60. html = html.replace(/<li(.*?)>(.*?)<\/li>/gi, "[*]$2");
  61. html = html.replace(/<ul(.*?)>/gi, "[list]");
  62. html = html.replace(/<\/ul>/gi, "[/list]");
  63. html = html.replace(/<div>/gi, "\n");
  64. html = html.replace(/<\/div>/gi, "\n");
  65. /*html = html.replace(/<td(.*?)>/gi, " ");
  66. html = html.replace(/<tr(.*?)>/gi, "\n");//*/
  67.  
  68. /*html = html.replace(/<img(.*?)src="(.*?)"(.*?)>/gi, "[img]$2[/img]");//*/
  69. html = html.replace(/<a(.*?)href="(.*?)"(.*?)>(.*?)<\/a>/gi, "[url=$2]$4[/url]");
  70.  
  71. html = html.replace(/<head>(.*?)<\/head>/gmi, "");
  72. html = html.replace(/<object>(.*?)<\/object>/gmi, "");
  73. html = html.replace(/<script(.*?)>(.*?)<\/script>/gmi, "");
  74. html = html.replace(/<style(.*?)>(.*?)<\/style>/gmi, "");
  75. html = html.replace(/<title>(.*?)<\/title>/gmi, "");
  76. html = html.replace(/<!--(.*?)-->/gmi, "\n");
  77. /*custom baha🚚*/
  78. html = html.replace(/<img(.*?)src="(.*?)"(.*?)width="(.*?)"(.*?)>/gi, "[img=$2 width=$4]");
  79. html = html.replace(/<img(.*?)src="(.*?)"(.*?)>/gi, "[img=$2]");
  80. html = html.replace(/<font face="(.*?)">(.*?)<\/font>/gi, "[font=$1]$2[/font]");
  81. html = html.replace(/<font face="(.*?)">\n<\/font>/gi, "[font=$1]\n[/font]");
  82. html = html.replace(/<font size="(.*?)">(.*?)<\/font>/gi, "[size=$1]$2[/size]");
  83. html = html.replace(/<strike>/gi, "[s]");
  84. html = html.replace(/<\/strike>/gi, "[/s]");
  85. html = html.replace(/<iframe(.*?)data-src="(.*?)"(.*?)>/gi, "[movie=$2]");
  86. html = html.replace(/<table(.*?)>/gi, "[table$1]");
  87. html = html.replace(/width="(.*?)"/gi, "width=$1");
  88. html = html.replace(/border="(.*?)"/gi, "border=$1");
  89. html = html.replace(/cellspacing="(.*?)"/gi, "cellspacing=$1");
  90. html = html.replace(/cellpadding="(.*?)"/gi, "cellpadding=$1");
  91. html = html.replace(/<\/table>/gi, "[/table]");
  92. html = html.replace(/<tbody>/gi, "[tbody]");
  93. html = html.replace(/<tr>/gi, "[tr]");
  94. html = html.replace(/<td>/gi, "[td]");
  95. html = html.replace(/<\/tbody>/gi, "[/tbody]");
  96. html = html.replace(/<\/tr>/gi, "[/tr]");
  97. html = html.replace(/<\/td>/gi, "[/td]");
  98. html = html.replace(/<hr>/gi, "[hr]");
  99. html = html.replace(/<br>/gi, "[br]");
  100.  
  101. /*html = html.replace(/\/\//gi, "/");
  102. html = html.replace(/http:\//gi, "http://");
  103. html = html.replace(/https:\//gi, "https://");//*/
  104.  
  105. html = html.replace(/<(?:[^>'"]*|(['"]).*?\1)*>/gmi, "");
  106. html = html.replace(/\r\r/gi, "");
  107. html = html.replace(/\[img]\//gi, "[img]");
  108. html = html.replace(/\[url=\//gi, "[url=");
  109.  
  110. html = html.replace(/(\S)\n/gi, "$1 ");
  111.  
  112. ////html = html.replace(/\[br]/gi, "\n");
  113. return html;
  114. }
  115. //console.log("break");
  116. function copy(selectors){
  117. let article=document.querySelectorAll(selectors)[0].cloneNode(true);
  118. let script=article.querySelectorAll('script');
  119. for(let i = 0; i<script.length; i++){script[i].remove();}
  120. let iframe=article.querySelectorAll('iframe');
  121. for(let i = 0; i<iframe.length; i++){
  122. let url=fn_url(iframe[i].getAttribute("data-src"));
  123. iframe[i].setAttribute("data-src","https://"+url[0].host+url[0].pathname.replace(/embed\//gi, "watch?v="));
  124. }
  125. let innerHTML=article.innerHTML;
  126. let tmp=fn_htmlToBBCode(innerHTML);
  127. console.log("copy");
  128. return tmp;
  129. }
  130. function menu_01(selectors){
  131. let tmp=copy(selectors);
  132. let ary_str=tmp.split('\n');
  133. let str_bbcode="";
  134. for(let i = 0; i<ary_str.length; i++){
  135. if(ary_str[i]==""){
  136. str_bbcode+="[div]\n[/div]";
  137. }else{
  138. str_bbcode+="[div]"+ary_str[i]+"[/div]";
  139. }
  140. }
  141. GM_setClipboard(str_bbcode.replace(/\[br]/gi, "\n").replace(/] \[/gi, "]["), "text");
  142. }
  143. function menu_02(selectors){
  144. let tmp=copy(selectors);
  145. GM_setClipboard(tmp.replace(/\[br]/gi, "\n"), "text");
  146. }
  147. (function() {
  148. 'use strict';
  149. let url=fn_url(document.location);
  150. if(url[0].host.search(new RegExp("web.archive.org", "i"))==0){
  151. if(url[0].pathname.search(/\/web\/\d+\*\//i)==0)return;
  152. }
  153. /*if(url[0].host.search(new RegExp("guild.gamer.com.tw", "i"))==0&&url[0].pathname.search(/\/about/i)==0){//guild
  154. GM_registerMenuCommand("sidebar_section_about-box", () => {
  155. menu_01('div.sidebar_section_about-box');
  156. });
  157. GM_registerMenuCommand("sidebar_section_announcement", () => {
  158. menu_02('div.sidebar_section_announcement');
  159. });
  160. }else{//artwork*/
  161. GM_registerMenuCommand("copy", () => {
  162. menu_01('div#article_content');
  163. });
  164. GM_registerMenuCommand("copy without [div]", () => {
  165. menu_02('div#article_content');
  166. });
  167. //}
  168. })();