H2B.js

A Javascript library that converts HTML to BBCode.

Tento skript by neměl být instalován přímo. Jedná se o knihovnu, kterou by měly jiné skripty využívat pomocí meta příkazu // @require https://update.greatest.deepsurf.us/scripts/371660/624615/H2Bjs.js

  1. // ==UserScript==
  2. // @name H2B.js
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description A Javascript library that converts HTML to BBCode.
  6. // @author You
  7. // @match *
  8. // @require https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js
  9. // @grant none
  10. // ==/UserScript==
  11. this.$ = this.jQuery = jQuery.noConflict(true);
  12. this.$.expr[':'].css = function(obj, index, meta) {
  13. var args = meta[3].split(/\s*,\s*/);
  14. return $(obj).css(args[0]) === args[1];
  15. };
  16. window.H2B = (function (){
  17. 'use strict';
  18. function arrayUnique(array, property) {
  19. var a = array.concat();
  20. var i, j;
  21. if (property) {
  22. for (i = 0; i < a.length; ++i) {
  23. for (j = i + 1; j < a.length; ++j) {
  24. if(a[i][property] === a[j][property]){
  25. a.splice(j--, 1);
  26. }
  27. }
  28. }
  29. } else {
  30. for (i = 0; i < a.length; ++i) {
  31. for (j = i + 1; j < a.length; ++j) {
  32. if (a[i] === a[j]){
  33. a.splice(j--, 1);
  34. }
  35. }
  36. }
  37. }
  38. return a;
  39. }
  40. function BBTagRule(html_selector_l, nth_parent_s2l, html_tag_count, post_equal_info, bbtag_name){
  41. //Properties
  42. this.HTMLSelectorL = html_selector_l;
  43. this.NthParentS2L = nth_parent_s2l;
  44. this.HTMLTagCount = html_tag_count;
  45. this.PostEqualInfo = post_equal_info;
  46. this.BBTagName = bbtag_name;
  47. //Methods
  48. if(typeof this.getTarget !== 'function'){
  49. BBTagRule.prototype.getTarget = function(mother_obj){
  50. var target_obj = {
  51. location: null,
  52. substituion: null
  53. };
  54. target_obj.location = mother_obj.find(this.HTMLSelectorL).add(mother_obj.filter(this.HTMLSelectorL)).sort(function(a, b){
  55. return $(b).parents().length - $(a).parents().length;
  56. });
  57. if(this.NthParentS2L >= 0){
  58. var that = this;
  59. target_obj.substituion = target_obj.location.map(function(){
  60. return $(this).parents().eq(that.NthParentS2L)[0];
  61. });
  62. }
  63. else{
  64. target_obj.substituion = target_obj.location;
  65. }
  66. return target_obj;
  67. };
  68. }
  69. if(typeof this.updateTarget !== 'function'){
  70. BBTagRule.prototype.updateTarget = function(mother_obj){
  71. var target_obj = this.getTarget(mother_obj);
  72. this.PostEqualInfo.modifyTag(target_obj, this.BBTagName);
  73. };
  74. }
  75. }
  76. function MoreInfo(info_type, info_name, info_RegExp, info_cap_num, info_case_sensitive){
  77. //Properties
  78. this.InfoType = info_type;
  79. this.InfoName = info_name;
  80. this.InfoRegExp = info_RegExp;
  81. this.InfoCapNum = info_cap_num;
  82. this.InfoCaseSensitve = info_case_sensitive;
  83. //Methods
  84. if(typeof this.modifyTag !== 'function'){
  85. MoreInfo.prototype.modifyTag = function(target_obj, bbtag_name){
  86. var that = this;
  87. target_obj.substituion.map(function(ind, e){
  88. if(that.InfoType){
  89. var info = $(e)[that.InfoType](that.InfoName);
  90. if((e.tagName === 'IMG') && (!(info && validURL(info)))){
  91. info = $(e)[that.InfoType]('src');
  92. }
  93. try{
  94. var info_bb = info.match(that.InfoRegExp)[that.InfoCapNum];
  95. e.outerHTML = '<' + bbtag_name + '=' + encodeURIComponent(info_bb) +
  96. ' class="$ez_h2b$"' +
  97. (that.InfoCaseSensitve?(' _ez-upper_="' + getUpperLocation(info_bb) + '">'):'>') +
  98. target_obj.location[ind].innerHTML + '</' + bbtag_name + '>';
  99. }
  100. catch(error){
  101. H2B.moreinfo_error_cbk();
  102. console.log(that);
  103. console.log(error);
  104. }
  105. }
  106. else{
  107. try{
  108. e.outerHTML = '<' + bbtag_name + ' class="$ez_h2b$">' +
  109. target_obj.location[ind].innerHTML +
  110. '</' + bbtag_name + '>';
  111. }
  112. catch(error){
  113. H2B.moreinfo_error_cbk();
  114. console.log(error);
  115. }
  116. }
  117. return e;
  118. });
  119. };
  120. }
  121. }
  122. function Replacer(rep_RegExp, rep_replacer){
  123. this.RepRegExp = rep_RegExp;
  124. this.RepReplacer = rep_replacer;
  125. if(typeof this.replaceThis !== 'function'){
  126. Replacer.prototype.replaceThis = function(text){
  127. return text.replace(this.RepRegExp, this.RepReplacer);
  128. };
  129. }
  130. }
  131. function getUpperLocation(text){
  132. var upper_info = [];
  133. var char = '';
  134. for (var i = 0; i < text.length; i++) {
  135. char = text.charCodeAt(i);
  136. if(char >= 65 && char<=90){
  137. upper_info.push(i);
  138. }
  139. }
  140. if(!upper_info.length){
  141. return -1;
  142. }
  143. return upper_info.join(';');
  144. }
  145. function hex(x){
  146. return ("0" + parseInt(x).toString(16)).slice(-2);
  147. }
  148. function validURL(str){
  149. var pattern = /^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})).?)(?::\d{2,5})?(?:[/?#]\S*)?$/i;
  150. if(!pattern.test(str)){
  151. return false;
  152. }
  153. else{
  154. return true;
  155. }
  156. }
  157. function uniRep(txt){
  158. H2B.universe_replace.forEach(function(e){
  159. txt = e.replaceThis(txt);
  160. });
  161. return txt;
  162. }
  163. function finalRep(txt){
  164. H2B.final_replace.forEach(function(e){
  165. txt = e.replaceThis(txt);
  166. });
  167. return txt;
  168. }
  169. function deCode(txt){
  170. txt = txt.replace(/<([^=>]+=)?([^> ]+)( _ez-upper_="([^>"]+)")?>/gi, function(match, p1, p2, p3, p4){
  171. //BBtags without "=XXX"
  172. if((!p1)&&p2&&(!p3)){
  173. return '[' + p2 + ']';
  174. }
  175. //BBtags with "=XXX" but without captitalized characters
  176. else if(p1&&p2&&(!p3)){
  177. try{
  178. p2 = decodeURIComponent(p2);
  179. }
  180. catch(error){}
  181. if((p1 === 'color=') && !(/^#[0-9A-F]{6}$/i.test(p2))){
  182. var rgb_array = null;
  183. if((rgb_array = p2.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/))){
  184. p2 = "#" + hex(rgb_array[1]) + hex(rgb_array[2]) + hex(rgb_array[3]);
  185. }
  186. }
  187. if((p1 === 'url=')||(p1 === 'img=')){
  188. H2B.redirect_list.forEach(function(e){
  189. p2 = e.replaceThis(p2);
  190. });
  191. }
  192. return '[' + p1 + p2 + ']';
  193. }
  194. //BBtags with "=XXX" with captitalized characters
  195. else if(p1&&p2&&p3){
  196. try{
  197. p2 = decodeURIComponent(p2);
  198. }
  199. catch(error){}
  200. var new_p = p2.split('');
  201. p4.split(';').forEach(function(e){
  202. new_p[e] = new_p[e].toUpperCase();
  203. });
  204. p2 = new_p.join('');
  205. //Strip off redirection prefix
  206. if((p1 === 'url=')||(p1 === 'img=')){
  207. H2B.redirect_list.forEach(function(e){
  208. p2 = e.replaceThis(p2);
  209. });
  210. }
  211. return '[' + p1 + p2 + ']';
  212. }
  213. });
  214. return txt;
  215. }
  216. var H2B ={
  217. gazelle_uni_rules: {
  218. 'base': /.+/,
  219. 'rules': {
  220. 'jquery': {
  221. 'b': new BBTagRule('strong', -1, 2, new MoreInfo(), 'b'),
  222. 'i': new BBTagRule('em', -1, 2, new MoreInfo(), 'i'),
  223. 'u': new BBTagRule('span:css(text-decoration, underline)', -1, 2, new MoreInfo(), 'u'),
  224. 'u1': new BBTagRule('u', -1, 2, new MoreInfo(), 'u'),
  225. 's': new BBTagRule('span:css(text-decoration, line-through)', -1, 2, new MoreInfo(), 's'),
  226. 's1': new BBTagRule('s', -1, 2, new MoreInfo(), 's'),
  227. 'hr': new BBTagRule('hr', -1, 1, new MoreInfo(), 'hr'),
  228. 'p': new BBTagRule('p:not(blockquote.quote>p,p.sub)', -1, 2, new MoreInfo(), 'paragraph'),
  229. 'spoiler': new BBTagRule('div>div.quotetitle+div.quotecontent>div', 1, 2, new MoreInfo(), 'spoiler'),
  230. 'spoiler1': new BBTagRule('blockquote.spoiler', -1, 2, new MoreInfo(), 'spoiler'),
  231. 'spoiler2': new BBTagRule('div[style*="margin-top:5px; padding:5px; border: 1px solid #333"]>div[style^="display"]', -1, 2, new MoreInfo(), 'spoiler'),
  232. 'align': new BBTagRule('div[style*="text-align"]', -1, 2, new MoreInfo('css', 'text-align', /center|left|right/i, 0, 0), 'align'),
  233. 'color': new BBTagRule('span[style*="color"]:not(.spoiler)', -1, 2, new MoreInfo('css', 'color', /.+/, 0, 0), 'color'),
  234. 'font': new BBTagRule('span[style*="font-family"]', -1, 2, new MoreInfo('css', 'font-family', /.+/, 0, 0), 'font'),
  235. 'size': new BBTagRule('span[class^="size"],span[class^="bbcode-size-"]', -1, 2, new MoreInfo('prop', 'class', /\d+/, 0, 0), 'size'),
  236. 'url': new BBTagRule('a[href]:not([onclick^="QuoteJump"])', -1, 2, new MoreInfo('prop', 'href', /.+/, 0, 1), 'url'),
  237. 'img': new BBTagRule('img[src]', -1, 1, new MoreInfo('prop', 'alt', /.+/, 0, 1), 'img'),
  238. 'quote': new BBTagRule('blockquote:not(.spoiler)', -1, 2, new MoreInfo(), 'quote'),
  239. 'quote1': new BBTagRule('a[onclick^="QuoteJump"]', -1, 2, new MoreInfo('attr', 'onclick', /QuoteJump\(event, '[^']+'\)/, 0, 0), 'url'),
  240. 'star': new BBTagRule('li', -1, 1, new MoreInfo(), 'star'),
  241. 'pre': new BBTagRule('pre:not(.prettyprint.linenums)', -1, 2, new MoreInfo(), 'pre'),
  242. 'code': new BBTagRule('code', -1, 2, new MoreInfo(), 'code'),
  243. 'comparison': new BBTagRule('a[onclick^="BBCode.ScreenshotComparisonToggleShow"]', -1, 2, new MoreInfo('attr', 'onclick', /.+/, 0, 1), 'comparison'),
  244. 'indent': new BBTagRule('div.bbcode_indent', -1, 2, new MoreInfo(), 'indent'),
  245. 'video': new BBTagRule('iframe.youtube-player', -1, 2, new MoreInfo('prop', 'src', /embed\/([^?]+)\?/, 1, 1), 'video')
  246. },
  247. 'string': {
  248. 'quote': new Replacer(/<b class="\$ez_h2b\$">([^<]+)<\/b> [wW]rote: (<quote)( class="\$ez_h2b\$")>/g, function(match, p1, p2, p3){
  249. return p2 + '=' + encodeURIComponent(p1) + p3 + ' _ez-upper_="' + getUpperLocation(p1) + '">';
  250. }),
  251. 'quote1': new Replacer(/<url=quotejump\(event%2c%20'([^']+)'\) class="\$ez_h2b\$"><b class="\$ez_h2b\$">([^<]+)<\/b> [wW]rote: <\/url=[^>]+>(<quote)( class="\$ez_h2b\$")>/g, function(match, p1, p2, p3, p4){
  252. return p3 + '=' + encodeURIComponent(p2 + '|' + p1 + '|undefined') + p4 + ' _ez-upper_="' + getUpperLocation(p2) + '">';
  253. }),
  254. 'quote2': new Replacer(/<b class="\$ez_h2b\$">([^<]+) [wW]rote: <\/b>(<quote)( class="\$ez_h2b\$")>/g, function(match, p1, p2, p3){
  255. return p2 + '=' + encodeURIComponent(p1) + p3 + ' _ez-upper_="' + getUpperLocation(p1) + '">';
  256. }),
  257. 'quote3': new Replacer(/<b class="\$ez_h2b\$">([^<]+) [wW]rote:<\/b> <url=([^>]+)><img=[^>]+><\/img=[^>]+><\/url=[^>]+>(<quote)( class="\$ez_h2b\$")>/g, function(match, p1, p2, p3, p4){
  258. try{
  259. return p3 + '=' + encodeURIComponent(p1 + ':f' + p2.match(/threadid%3d([^%]+)%/)[1] + ':' + p2.match(/postid%3d([^%]+)%/)[1]) + p4 + ' _ez-upper_="' + getUpperLocation(p1) + '">';
  260. }
  261. catch(error){
  262. return p3 + '=' + encodeURIComponent(p1 + ':t' + p2.match(/%3fid%3d([^%]+)%/)[1] + ':' + p2.match(/postid%3d([^%]+)%/)[1]) + p4 + ' _ez-upper_="' + getUpperLocation(p1) + '">';
  263. }
  264. }),//
  265. 'spoiler1': new Replacer(/<b class="\$ez_h2b\$">([^<]+)<\/b>: <url=[^>]+>(?:Hide|Show)<\/url=[^>]+>(<spoiler)( class="\$ez_h2b\$")>/g, function(match, p1, p2 ,p3){
  266. if(p1==='Hidden text'){
  267. return p2 + p3 +'>';
  268. }
  269. else{
  270. return p2 + '=' + encodeURIComponent(p1) + p3 + ' _ez-upper_="' + getUpperLocation(p1) + '">';
  271. }
  272. }),
  273. 'spoiler2': new Replacer(/<b class="\$ez_h2b\$">([^<]+)<\/b> <url=[^>]+>\[(?:hide|show)\]<\/url=[^>]+>(<spoiler)( class="\$ez_h2b\$")>/g, function(match, p1, p2 ,p3){
  274. if(p1==='Spoiler'){
  275. return p2 + p3 +'>';
  276. }
  277. else{
  278. return p2 + '=' + encodeURIComponent(p1) + p3 + ' _ez-upper_="' + getUpperLocation(p1) + '">';
  279. }
  280. }),
  281. 'hide': new Replacer(/<b class="\$ez_h2b\$">([^<]+)<\/b>: <url=[^>]+>(?:Hide|Show)<\/url=[^>]+>(<hide)( class="\$ez_h2b\$")>/g, function(match, p1, p2 ,p3){
  282. if(p1==='Spoiler'){
  283. return p2 + p3 +'>';
  284. }
  285. else{
  286. return p2 + '=' + encodeURIComponent(p1) + p3 + ' _ez-upper_="' + getUpperLocation(p1) + '">';
  287. }
  288. }),
  289. 'mi': new Replacer(/<url=[^>]+>[^<]+<\/url=[^>]+><hide class="\$ez_h2b\$">((?:(?!<\/hide>)[\s\S])+)<\/hide>/g, '<mi class="$ez_h2b$">$1</mi>'),
  290. 'img': new Replacer(/<\/img=[^>]+>/g, ''),
  291. 'url': new Replacer(/<url=[^>]+><\/url=[^>]+>/g, ''),
  292. 'hr': new Replacer(/<\/hr>/g, ''),
  293. 'comparison': new Replacer(/<b class="\$ez_h2b\$">[^<]+<\/b>: <comparison=([^ >]+) class="\$ez_h2b\$" _ez-upper_="([^"]+)">Show comparison<\/comparison=[^>]+>/g, function(match, p1, p2){
  294. p1 = decodeURIComponent(p1);
  295. var new_p = p1.split('');
  296. if(p2!=='-1'){
  297. p2.split(';').forEach(function(e){
  298. new_p[e] = new_p[e].toUpperCase();
  299. });
  300. }
  301. p1 = new_p.join('').replace(/\\\//g,'/');
  302. return p1.replace(/^[^[]+\[([^\]]+)\], \[([^\]]+)\].+$/, function(match, sp1, sp2){
  303. var info_bb = sp1.split(',').map(function(e){
  304. return e.slice(1,-1);
  305. }).join(',');
  306. var inner_txt = sp2.split(',').map(function(e){
  307. return e.slice(1,-1);
  308. }).join('<br>');
  309. return '<comparison=' + encodeURIComponent(info_bb) + ' class="$ez_h2b$" _ez-upper_="' + getUpperLocation(info_bb) + '">' + inner_txt + '</comparison=' + encodeURIComponent(info_bb) + '>';
  310. });
  311. }),
  312. 'video': new Replacer(/<video=([^> ]+) class="\$ez_h2b\$" _ez-upper_="([^"]+)"><\/video=[^>]+>/, function(match, p1, p2){
  313. p1 = decodeURIComponent(p1);
  314. var new_p = p1.split('');
  315. if(p2!=='-1'){
  316. p2.split(';').forEach(function(e){
  317. new_p[e] = new_p[e].toUpperCase();
  318. });
  319. }
  320. p1 = new_p.join('');
  321. return '<video class="$ez_h2b$">http://www.youtube.com/watch?v=' + p1 + '</video>';
  322. }),
  323. 'mention': new Replacer(/<user class="\$ez_h2b\$">(@[^<]+)<\/user>/g, '$1')
  324. }
  325. }
  326. },
  327. nexusphp_uni_rules: {
  328. 'base': /.+/,
  329. 'rules': {
  330. 'jquery': {
  331. 'b': new BBTagRule('b:not(blockquote.quote>span.nowrap>a.username>b)', -1, 2, new MoreInfo(), 'b'),
  332. 'b2': new BBTagRule('strong', -1, 2, new MoreInfo(), 'b'),
  333. 'i': new BBTagRule('i', -1, 2, new MoreInfo(), 'i'),
  334. 'u': new BBTagRule('u', -1, 2, new MoreInfo(), 'u'),
  335. 'del': new BBTagRule('del', -1, 2, new MoreInfo(), 'del'),
  336. 'hr': new BBTagRule('hr', -1, 1, new MoreInfo(), 'hr'),
  337. 'center': new BBTagRule('div[style*="text-align:center"]', -1, 2, new MoreInfo(), 'center'),
  338. 'center2': new BBTagRule('center', -1, 2, new MoreInfo(), 'center'),
  339. 'center3': new BBTagRule('div[align*="center"]', -1, 2, new MoreInfo(), 'center'),
  340. 'right': new BBTagRule('div[style*="text-align:right"]', -1, 2, new MoreInfo(), 'right'),
  341. 'right2': new BBTagRule('div[align*="right"]', -1, 2, new MoreInfo(), 'right'),
  342. 'left': new BBTagRule('div[style*="text-align:left"]', -1, 2, new MoreInfo(), 'left'),
  343. 'left2': new BBTagRule('div[align*="left"]', -1, 2, new MoreInfo(), 'left'),
  344. 'color': new BBTagRule('span[style*="color"]', -1, 2, new MoreInfo('css', 'color', /.+/, 0, 0), 'color'),
  345. 'color2': new BBTagRule('font[color]', -1, 2, new MoreInfo('prop', 'color', /.+/, 0, 0), 'color'),
  346. 'font': new BBTagRule('font[face]', -1, 2, new MoreInfo('prop', 'face', /.+/, 0, 0), 'font'),
  347. 'size': new BBTagRule('font[size]', -1, 2, new MoreInfo('prop', 'size', /.+/, 0, 0), 'size'),
  348. 'url': new BBTagRule('a[href]:not(.username)', -1, 2, new MoreInfo('prop', 'href', /.+/, 0, 1), 'url'),
  349. 'img': new BBTagRule('img[src]:not(.listicon)', -1, 1, new MoreInfo('prop', 'src', /.+/, 0, 1), 'img'),
  350. 'p': new BBTagRule('p:not(blockquote.quote>p,p.sub)', -1, 2, new MoreInfo(), 'paragraph'),
  351. 'quotehead': new BBTagRule('blockquote.quote>p,p.sub', -1, 2, new MoreInfo(), 'quotehead'),
  352. 'quotehead2': new BBTagRule('blockquote.quote>span.nowrap>a.username>b', 1, 2, new MoreInfo(), 'quotehead'),
  353. 'quote': new BBTagRule('fieldset,blockquote.quote', -1, 2, new MoreInfo(), 'quote'),
  354. 'quote2': new BBTagRule('table.main>tbody>tr>td[style*="dotted"]', 2, 2, new MoreInfo(), 'quote'),
  355. 'xp': new BBTagRule('img.listicon', -1, 1, new MoreInfo(), 'xp'),
  356. 'ol': new BBTagRule('ol', -1, 2, new MoreInfo(), 'ol'),
  357. 'ul': new BBTagRule('ul', -1, 2, new MoreInfo(), 'ul'),
  358. 'li': new BBTagRule('ol>li, ul>li', -1, 2, new MoreInfo(), 'li'),
  359. 'star': new BBTagRule('li:not(ol>li, ul>li)', -1, 1, new MoreInfo(), 'star'),
  360. 'pre': new BBTagRule('pre:not(.prettyprint.linenums)', -1, 2, new MoreInfo(), 'pre'),
  361. 'pre2': new BBTagRule('tt>nobr', 0, 2, new MoreInfo(), 'pre'),
  362. 'code': new BBTagRule('div.codemain', -1, 2, new MoreInfo(), 'code'),
  363. 'code2': new BBTagRule('pre.prettyprint.linenums', -1, 2, new MoreInfo(), 'code'),
  364. 'box': new BBTagRule('div.spoiler_body', -1, 2, new MoreInfo(), 'box'),
  365. 'boxhead': new BBTagRule('div.spoiler_head', -1, 2, new MoreInfo(), 'boxhead'),
  366. 'table': new BBTagRule('table', -1, 2, new MoreInfo(), 'table'),
  367. 'tr': new BBTagRule('tr', -1, 2, new MoreInfo(), 'tr'),
  368. 'td': new BBTagRule('td', -1, 2, new MoreInfo(), 'td')
  369. },
  370. 'string': {
  371. 'img': new Replacer(/<\/img=[^>]+>/g, ''),
  372. 'url': new Replacer(/<url=[^>]+><\/url=[^>]+>/g, ''),
  373. 'quote': new Replacer(/(<quote)( class="\$ez_h2b\$")>[^:<]+:? (?:([^<]+) )?<br>/g, function(match, p1, p2, p3){
  374. if(p3){
  375. return p1 + '=' + encodeURIComponent(p3) + p2 + ' _ez-upper_="' + getUpperLocation(p3) + '">';
  376. }
  377. else{
  378. return p1 + p2 + '>';
  379. }
  380. }),
  381. 'quote2': new Replacer(/(<quote)( class="\$ez_h2b\$")>(?:引用: )?(?:<quotehead class="\$ez_h2b\$">)?([^<]+)(?:<\/quotehead><br>|<\/quotehead>|<br>)/g, function(match, p1, p2, p3){
  382. if(p3 !== ' 引用 '){
  383. return p1 + '=' + encodeURIComponent(p3) + p2 + ' _ez-upper_="' + getUpperLocation(p3) + '">';
  384. }
  385. else{
  386. return p1 + p2 + '>';
  387. }
  388. }),
  389. 'quote3': new Replacer(/<quotehead class="\$ez_h2b\$"><b class="\$ez_h2b\$">(?:([^<]+) wrote:|Quote:)<\/b><\/quotehead>(<quote)( class="\$ez_h2b\$")>/g, function(match, p1, p2, p3){
  390. if(p1){
  391. return p2 + '=' + encodeURIComponent(p1) + p3 + ' _ez-upper_="' + getUpperLocation(p1) + '">';
  392. }
  393. else{
  394. return p2 + p3 + '>';
  395. }
  396. }),
  397. 'box': new Replacer(/<boxhead class="\$ez_h2b\$">([^<]*)<\/boxhead>(<box)( class="\$ez_h2b\$")>/g, function(match, p1, p2, p3){
  398. if(p1 && p1!=='collapsed text' && p1!=='隐藏内容'){
  399. return p2 + '=' + encodeURIComponent(p1) + p3 + ' _ez-upper_="' + getUpperLocation(p1) + '">';
  400. }
  401. else{
  402. return p2 + p3 + '>';
  403. }
  404. }),
  405. 'hr': new Replacer(/<\/hr>/g, ''),
  406. 'codeend': new Replacer(/(<\/code>)<br>/g, '$1'),
  407. 'codehead': new Replacer(/<br>(<code class="\$ez_h2b\$">)/g, '$1'),
  408. }
  409. }
  410. },
  411. universe_replace: [
  412. new Replacer(/<([^> ]+) class="\$ez_h2b\$"/g, '<$1'),
  413. new Replacer(/ _ez-upper_="-1"/g, ''),
  414. new Replacer(/\n/g, ''),
  415. new Replacer(/<br>/g, '\n'),
  416. new Replacer(/(<\/[^=>]+)=[^>]+>/g, '$1>'),
  417. new Replacer(/([^\n])<star>/g, '$1\n<star>'),
  418. new Replacer(/([^\n])<xp>/g, '$1\n<xp>'),
  419. new Replacer(/<\/star>([^\n])/g, '\n$1'),
  420. new Replacer(/<\/star>/g, ''),
  421. new Replacer(/<\/xp>/g, ''),
  422. new Replacer(/<star>/g, '<*>'),
  423. new Replacer(/<xp>/g, '<*>'),
  424. new Replacer(/<paragraph>/g, ''),
  425. new Replacer(/<\/paragraph>/g, '\n'),
  426. new Replacer(/<\/?tbody>/g, ''),
  427. new Replacer(/&quote;/g, '"'),
  428. new Replacer(/&lt;/g, '<'),
  429. new Replacer(/&gt;/g, '>'),
  430. new Replacer(/&amp;/g, '&'),
  431. new Replacer(/&nbsp;/g, ' ')
  432. ],
  433. final_replace: [
  434. new Replacer(/\[img=([^\]]+)](?:\[\/img\])?/g, '[img]$1[/img]'),
  435. ],
  436. redirect_list: [
  437. new Replacer(/^https?:\/\/anonym\.to\/\?(.+$)/, '$1'),
  438. new Replacer(/^https?:\/\/anon\.to\/\?(.+$)/, '$1'),
  439. new Replacer(/^https?:\/\/nullrefer\.com\/\?(.+$)/, '$1'),
  440. new Replacer(/^https?:\/\/blankrefer\.com\/\?(.+$)/, '$1'),
  441. new Replacer(/^https?:\/\/www\.dereferer\.org\/\?(.+$)/, function(match, p1){
  442. return decodeURIComponent(p1);
  443. })//...to be continued
  444. ],
  445. black_list: ['script','table.mediainfo','div.codetop','span.fa'].join(',')
  446. };
  447. /*--AHD--*/
  448. H2B.ahd_rules = $.extend(true, {}, H2B.gazelle_uni_rules);
  449. H2B.ahd_rules.base = 'awesome-hd.me';
  450. /*--UHD--*/
  451. H2B.uhd_rules = $.extend(true, {}, H2B.gazelle_uni_rules);
  452. H2B.uhd_rules.base = 'uhdbits.org';
  453. delete H2B.uhd_rules.rules.string.img;
  454. delete H2B.uhd_rules.rules.string.url;
  455. /*--PTP--*/
  456. H2B.ptp_rules = $.extend(true, {}, H2B.gazelle_uni_rules);
  457. H2B.ptp_rules.base = 'passthepopcorn.me';
  458. H2B.ptp_rules.rules.jquery.spoiler1 = new BBTagRule('span.spoiler', -1, 2, new MoreInfo(), 'spoiler');
  459. H2B.ptp_rules.rules.jquery.hide = new BBTagRule('blockquote.spoiler', -1, 2, new MoreInfo(), 'hide');
  460. H2B.ptp_rules.rules.jquery.user = new BBTagRule('a[href^="user.php?action=search&search="]', -1, 2, new MoreInfo(), 'user');
  461. H2B.ptp_rules.rules.jquery.artist = new BBTagRule('a[href^="artist.php?artistname="]', -1, 2, new MoreInfo(), 'artist');
  462. H2B.ptp_rules.rules.jquery.movie = new BBTagRule('a[href^="torrents.php?searchstr="]', -1, 2, new MoreInfo(), 'movie');
  463. H2B.ptp_rules.rules.jquery.url = new BBTagRule('a[href]:not('+[
  464. H2B.ptp_rules.rules.jquery.user.HTMLSelectorL,
  465. H2B.ptp_rules.rules.jquery.artist.HTMLSelectorL,
  466. H2B.ptp_rules.rules.jquery.movie.HTMLSelectorL,
  467. H2B.ptp_rules.rules.jquery.comparison.HTMLSelectorL,
  468. ].join(',')+')', -1, 2, new MoreInfo('prop', 'href', /.+/i, 0, 1), 'url');
  469. /*--BTN--*/
  470. H2B.btn_rules = $.extend(true, {}, H2B.gazelle_uni_rules);
  471. H2B.btn_rules.base = 'broadcasthe.net';
  472. /*--NHD--*/
  473. H2B.nhd_rules = $.extend(true, {}, H2B.nexusphp_uni_rules);
  474. H2B.nhd_rules.base = 'nexushd.org';
  475. H2B.nhd_rules.rules.string.quoteend = new Replacer(/(<\/quote[^>]*>)<br>/g, '$1');
  476. /*--NPU--*/
  477. H2B.npu_rules = $.extend(true, {}, H2B.nexusphp_uni_rules);
  478. H2B.npu_rules.base = 'npupt.com';
  479. /*--TTG--*/
  480. H2B.ttg_rules = $.extend(true, {}, H2B.nexusphp_uni_rules);
  481. H2B.ttg_rules.base = 'totheglory.im';
  482. /*--HDChina--*/
  483. H2B.hdc_rules = $.extend(true, {}, H2B.nexusphp_uni_rules);
  484. H2B.hdc_rules.base = 'hdchina.org';
  485. /*--Ourbits--*/
  486. H2B.ob_rules = $.extend(true, {}, H2B.nexusphp_uni_rules);
  487. H2B.ob_rules.base = 'ourbits.club';
  488. /*--HDHome--*/
  489. H2B.hdh_rules = $.extend(true, {}, H2B.nexusphp_uni_rules);
  490. H2B.hdh_rules.base = 'hdhome.org';
  491. /*--TorViet--*/
  492. H2B.torviet_rules = $.extend(true, {}, H2B.nexusphp_uni_rules);
  493. H2B.torviet_rules.base = 'torviet.com';
  494. /*--Univers--*/
  495. H2B.universe_rules = {
  496. 'base': /.+/,
  497. 'rules': {
  498. 'jquery': null,
  499. 'string': null
  500. }
  501. };
  502. H2B.universe_rules.rules.jquery = arrayUnique(Object.values(H2B.nexusphp_uni_rules.rules.jquery).concat(Object.values(H2B.gazelle_uni_rules.rules.jquery)), null);
  503. H2B.universe_rules.rules.string = arrayUnique(Object.values(H2B.nexusphp_uni_rules.rules.string).concat(Object.values(H2B.gazelle_uni_rules.rules.string)), null);
  504. H2B.h2b_rules = [H2B.ahd_rules,
  505. H2B.uhd_rules,
  506. H2B.ptp_rules,
  507. H2B.btn_rules,
  508. H2B.nhd_rules,
  509. H2B.npu_rules,
  510. H2B.ttg_rules,
  511. H2B.hdc_rules,
  512. H2B.ob_rules,
  513. H2B.hdh_rules,
  514. H2B.torviet_rules];
  515. H2B.moreinfo_error_cbk = function(){return 0;},
  516. H2B.HTML2BBCode = function (content){
  517. var description_obj;
  518. description_obj = $('<ezentity>').append($(content).clone());
  519. description_obj.find(H2B.black_list).add(description_obj.filter(H2B.black_list)).remove();
  520. $(description_obj.find('*').add(description_obj.filter('*')).contents().filter(function(){
  521. return this.nodeType == 8;
  522. })).remove();
  523. var description_txt = description_obj[0].innerHTML.trim();
  524. if(!H2B.h2b_rules.some(function(e_0){
  525. if(window.location.href.match(e_0.base)){
  526. Object.values(e_0.rules.jquery).forEach(function(e_1){
  527. e_1.updateTarget(description_obj);
  528. });
  529. description_obj.find(':not([class="$ez_h2b$"],br)').sort(function(a, b){
  530. return $(b).parents().length - $(a).parents().length;
  531. }).map(function(){
  532. this.outerHTML = this.innerHTML;
  533. });
  534. description_txt = description_obj[0].innerHTML.trim();
  535. Object.values(e_0.rules.string).forEach(function(e_1){
  536. description_txt = e_1.replaceThis(description_txt);
  537. });
  538. return true;
  539. }
  540. })){
  541. H2B.universe_rules.rules.jquery.forEach(function(e_1){
  542. e_1.updateTarget(description_obj);
  543. });
  544. description_obj.find(':not([class="$ez_h2b$"],br)').sort(function(a, b){
  545. return $(b).parents().length - $(a).parents().length;
  546. }).map(function(){
  547. this.outerHTML = this.innerHTML;
  548. });
  549. description_txt = description_obj[0].innerHTML.trim();
  550. //console.log(description_txt);
  551. H2B.universe_rules.rules.string.forEach(function(e_1){
  552. description_txt = e_1.replaceThis(description_txt);
  553. });
  554. }
  555. description_txt = uniRep(description_txt);
  556. description_txt = deCode(description_txt);
  557. description_txt = finalRep(description_txt);
  558. return description_txt;
  559. }
  560. return H2B;
  561. }());