BBCode Generator

Generates BBCode for in game forum from the content of the current page

目前為 2014-08-01 提交的版本,檢視 最新版本

  1. //-----------------------------------------------------------------------------
  2. // [WoD] BBCode generator
  3. // Version 1.71, 2011-02-24
  4. //
  5. // Script aimed at players of World Of Dungeons. Generates BBCode for in game forum from the content of the current page
  6. //
  7. // A new button will appear at the left side of each page (below menu).
  8. // Pressing this button will generate BBCode representation of current page and append it at the bottom of the page.
  9. //-----------------------------------------------------------------------------
  10.  
  11.  
  12. //-----------------------------------------------------------------------------
  13. // Changelog
  14. // 1.71
  15. // - Adoption for org.
  16.  
  17. // 1.7
  18. // - internal optimizations regarding performance (many thanks to Finargol for pointing in right direction)
  19. //
  20. // 1.6
  21. // - now displaying <input> and <textarea> tag texts and images
  22. // - added ignore/don't display handling for bunch of html tags (which are probably not used by wod, but just to be safe)
  23. //
  24. // 1.5
  25. // - now displaying selected option inside <select> tag
  26. //
  27. // 1.4
  28. // - label instead of span by the checkboxes
  29. // - shortened all titles, english, french and croatian are ok, waiting for somebody who knows other languages to tell me if it is ok
  30. // - changed internal representation of localized strings to ease maintenance
  31. // - internal reorganization
  32. // - moved "BBCode create" button to the bottom of central part of the page (it confused some other scripts when placed on top, plus some users said it doesn't suit them when placed on top)
  33. // - added encodeuri to url handling to handle international characters in uris
  34. // - added Finargol to contributor list (thanks for useful input and testing on french server)
  35. //
  36. // 1.3
  37. // - included french translation and allowed all wod sites to use since should not depend on language used.
  38. // - added some translations (based on Google translate, corrections most welcome!!!)
  39. // - changed place where button and options are located to be consistent in popup pages where menu tree on left does not exist
  40. // - now handling urls without href
  41. // - fixed some minor formatting issues (newlines and tabs inside text)
  42. //
  43. // 1.2
  44. // - included font color and size in item, hero, group, monster, etc tags
  45. // - fixed problem with forum post ids
  46. // - added handling for monuments
  47. // - after code is created page is positioned at the beginning of created bbcode
  48. // - created BBCode placed inside text area box for easier copying
  49. //
  50. // 1.1
  51. // - changed how font size, family and size are handled
  52. // - added checkboxes so user can decide whether to include font size, family and size into BBCode created (plain text works better with various skins)
  53. // - added anonymous function around code so not to polute, or interact with, global namespace
  54. //
  55. // 1.0
  56. // - initial release
  57. //-----------------------------------------------------------------------------
  58.  
  59.  
  60. // ==UserScript==
  61. // @name BBCode Generator
  62. // @namespace tomy
  63. // @description Generates BBCode for in game forum from the content of the current page
  64. // @include http*://*.world-of-dungeons.*
  65. // @version 1.7
  66. // @contributor Finargol
  67. // @author Tomy
  68. // @copyright 2010+, Tomy
  69. // ==/UserScript==
  70.  
  71. (function() {
  72.  
  73. //-----------------------------------------------------------------------------
  74. // auxiliary functions
  75. //-----------------------------------------------------------------------------
  76.  
  77. // Usage: dump(object)
  78. function dump(object, pad){
  79. var indent = "\t";
  80. if (!pad) pad = '';
  81. var out = '';
  82. if (object == undefined) {
  83. out += "undefined";
  84. } else if (object.constructor == Array) {
  85. out += '[\n';
  86. for (var i = 0; i < object.length; ++i) {
  87. out += pad + indent + '[' + i + '] = ' + dump(object[i], pad + indent) + '\n';
  88. }
  89. out += pad + ']';
  90. } else if (object.constructor == Object || typeof object == 'object') {
  91. out += '{\n';
  92. for (var i in object) {
  93. if (typeof object[i] != 'function')
  94. out += pad + indent + i + ': ' + dump(object[i], pad + indent) + '\n';
  95. }
  96. out += pad + '}';
  97. } else {
  98. out += object;
  99. }
  100. return out;
  101. }
  102.  
  103. String.prototype.trim = function() {
  104. return this.replace(/^\s+|\s+$/g,"");
  105. }
  106.  
  107. String.prototype.startsWith = function(prefix) {
  108. return this.indexOf(prefix) == 0;
  109. };
  110.  
  111. String.prototype.endsWith = function(suffix) {
  112. return this.indexOf(suffix, this.length - suffix.length) !== -1;
  113. };
  114.  
  115. String.prototype.removeRight = function(suffix) {
  116. if (!this.endsWith(suffix)) return String(this);
  117. return String(this).substring(0, this.length - suffix.length);
  118. };
  119.  
  120. String.prototype.removeLeft = function(prefix) {
  121. if (!this.startsWith(prefix)) return String(this);
  122. return String(this).substring(prefix.length);
  123. };
  124.  
  125. function StyleCollection1(styleArray) {
  126. this.styleArray = styleArray;
  127. }
  128.  
  129. StyleCollection1.prototype.getStyle = function(styleProp) {
  130. return this.styleArray[styleProp];
  131. }
  132.  
  133. function StyleCollection2(styleObj) {
  134. this.styleObj = styleObj;
  135. }
  136.  
  137. StyleCollection2.prototype.getStyle = function(styleProp) {
  138. return this.styleObj.getPropertyValue(styleProp);
  139. }
  140.  
  141. function getStyleCollection(x)
  142. {
  143. if (x.currentStyle)
  144. return new StyleCollection1(x.currentStyle);
  145. else if (window.getComputedStyle) {
  146. return new StyleCollection2(document.defaultView.getComputedStyle(x,null));
  147. }
  148. return undefined;
  149. }
  150.  
  151. function getStyle(x,styleProp)
  152. {
  153. var styles = getStyleCollection(x);
  154. if (styles != undefined) return styles.getStyle(styleProp);
  155. else return undefined;
  156. }
  157.  
  158. function removeLastChild(node)
  159. {
  160. node.removeChild(node.lastChild);
  161. }
  162.  
  163. function DebugMsg(Data)
  164. {
  165. if (DEBUG)
  166. alert(dump(Data));
  167. }
  168.  
  169. //-----------------------------------------------------------------------------
  170. // "global" variables
  171. //-----------------------------------------------------------------------------
  172.  
  173. var DEBUG = true;
  174. var VER = "1.7";
  175. var LOCAL_VAR_NAME = "WOD_BBCode_Creator_Script";
  176.  
  177. var Result = undefined;
  178. var ButtonTable = undefined;
  179. var KeyButton = null;
  180. var MainContent = undefined;
  181.  
  182. var CheckBoxes = ["clr", "sz", "fnt"];
  183.  
  184. var DefaultSize = undefined;
  185. var DefaultFont = undefined;
  186. var DefaultColor = undefined;
  187. var DefaultLinkColor = undefined;
  188.  
  189. // en fr de it es pl hr
  190. var Contents = {
  191. "en" : {
  192. Button_Name : "Create BBCode"
  193. , BBCode_Header : "BBCode"
  194. , Copyright : "Created with BBCode Generator"
  195. , Include_Color : "color"
  196. , Include_Size : "font size"
  197. , Include_Font : "font"
  198. },
  199. "fr" : {
  200. Button_Name : "Créer BBCode"
  201. , BBCode_Header : "BBCode"
  202. , Copyright : "Créé avec BBCode Generator"
  203. , Include_Color : "couleur"
  204. , Include_Size : "taille du texte"
  205. , Include_Font : "police"
  206. },
  207. "de" : {
  208. Button_Name : "BBCode erstellen"
  209. , BBCode_Header : "BBCode"
  210. , Copyright : "Erstellt mit BBCode Generator"
  211. , Include_Color : "Farbe"
  212. , Include_Size : "Schriftgröße"
  213. , Include_Font : "Schriftart"
  214. },
  215. "it" : {
  216. Button_Name : "Crea BBCode"
  217. , BBCode_Header : "BBCode"
  218. , Copyright : "Creato con BBCode Generator"
  219. , Include_Color : "colore"
  220. , Include_Size : "dimensioni dei caratteri"
  221. , Include_Font : "font"
  222. },
  223. "es" : {
  224. Button_Name : "Crear BBCode"
  225. , BBCode_Header : "BBCode"
  226. , Copyright : "Creado con el BBCode Generator"
  227. , Include_Color : "color"
  228. , Include_Size : "el tama&ntilde;o de fuente"
  229. , Include_Font : "fuente"
  230. },
  231. "pl" : {
  232. Button_Name : "Tworzenie BBCode"
  233. , BBCode_Header : "BBCode"
  234. , Copyright : "Stworzony z BBCode Generator"
  235. , Include_Color : "kolorze"
  236. , Include_Size : "rozmiar czcionki"
  237. , Include_Font : "font"
  238. },
  239. "hr" : {
  240. Button_Name : "Napravi BBKod"
  241. , BBCode_Header : "BBKod"
  242. , Copyright : "Napravljeno sa BBCode Generator-om"
  243. , Include_Color : "boja"
  244. , Include_Size : "veli&#269;ina fonta"
  245. , Include_Font : "font"
  246. },
  247. "cn" : {
  248. Button_Name : "转化为 BBCode"
  249. , BBCode_Header : "BBCode"
  250. , Copyright : "Created with BBCode Generator"
  251. , Include_Color : "color"
  252. , Include_Size : "font size"
  253. , Include_Font : "font"
  254. }
  255. };
  256.  
  257. var Ignored = ["script", "noscript", "textarea", "#comment", "area", "caption", "col", "colgroup", "frame", "frameset", "iframe", "map", "noframes", "noscript", "object", "param", "script"];
  258. var NotDisplayed = ["select", "sup", "sub", "tbody", "thead", "tfoot", "form", "div", "span", "#text", "br", "font", "label", "textarea", "abbr", "acronym", "address", "applet", "bdo", "big", "blockquote", "button", "center", "cite", "code", "dfn", "fieldset", "kbd", "label", "legend", "optgroup", "q", "samp", "small", "tt", "var", "dl"];
  259. var NoEnd = ["p", "li", "hr", "dd"];
  260. var NameChange = {ul:"list", ol:"list", dir:"list", menu:"list", dt:"list", dd:"*", li:"*", a:"url", strike:"s", strong:"b", del:"s", ins:"u"};
  261. var NewLineBefore = ["h1", "h2", "h3", "h4", "h5", "li", "br"];
  262. var NewLineAfter = ["tr"];
  263.  
  264. var IgnoredImages = [
  265. "http://skins.world-of-dungeons.net/skins/finals/skin-2/images/icons/reset.gif"
  266. , "http://skins.world-of-dungeons.net/skins/finals/skin-2/images/icons/steigern_disabled.gif"
  267. , "http://skins.world-of-dungeons.net/skins/finals/skin-2/images/icons/undo_steigern_enabled.gif"
  268. , "http://skins.world-of-dungeons.net/skins/finals/skin-2/images/icons/steigern_enabled.gif"
  269. , "http://skins.world-of-dungeons.net/skins/finals/skin-2/images/icons/inf.gif"
  270. , "http://skins.world-of-dungeons.net/skins/finals/skin-2/images/page/spacer.gif"
  271. , "http://skins.world-of-dungeons.org/skins/finals/skin-3/images/icons/reset.gif"
  272. , "http://skins.world-of-dungeons.org/skins/finals/skin-2/images/icons/steigern_disabled.gif"
  273. , "http://skins.world-of-dungeons.org/skins/finals/skin-2/images/icons/undo_steigern_enabled.gif"
  274. , "http://skins.world-of-dungeons.org/skins/finals/skin-2/images/icons/steigern_enabled.gif"
  275. , "http://skins.world-of-dungeons.org/skins/finals/skin-2/images/icons/inf.gif"
  276. , "http://skins.world-of-dungeons.org/skins/finals/skin-2/images/page/spacer.gif"
  277. , "/wod/css//skins/skin-3/images/icons/inf.gif"
  278. ]
  279.  
  280. var SpecialURLs = [
  281. { url:"/wod/spiel/hero/item.php", bbcode:"item" }
  282. , { url:"/wod/spiel/hero/skill.php", bbcode:"skill" }
  283. , { url:"/wod/spiel/hero/profile.php", bbcode:"hero" }
  284. , { url:"/wod/spiel/hero/class.php", bbcode:"class" }
  285. , { url:"/wod/spiel/profiles/player.php", bbcode:"player" }
  286. , { url:"/wod/spiel/dungeon/group.php", bbcode:"group" }
  287. , { url:"/wod/spiel/clan/clan.php", bbcode:"clan" }
  288. , { url:"/wod/spiel/help/npc.php", bbcode:"monster" }
  289. , { url:"/wod/spiel/clan/item.php", bbcode:"monument" }
  290. ];
  291.  
  292. //-----------------------------------------------------------------------------
  293. // "initialization" functions
  294. //-----------------------------------------------------------------------------
  295.  
  296. function Main()
  297. {
  298. // Language selection
  299. if (GetLocalContents() == null) return;
  300.  
  301. // Add buttons
  302. KeyButton = Init(Contents.Button_Name, OnCreateBB);
  303. if (KeyButton == null) return;
  304. }
  305.  
  306. function Init(ButtonText, ButtonFunct)
  307. {
  308. MainContent = undefined;
  309.  
  310. var newButton = null;
  311. var main_body = document.getElementById("main_content");
  312. if (main_body != null && main_body != undefined)
  313. MainContent = main_body;
  314. else {
  315. var allDivs = document.getElementsByTagName("div");
  316. for (var i = 0; i < allDivs.length; ++i)
  317. if (allDivs[i].className == "gadget main_content popup")
  318. MainContent = allDivs[i];
  319. }
  320. if (MainContent != undefined) {
  321. var allInputs = MainContent.getElementsByTagName("div");
  322. for (var i = 0; i < allInputs.length; ++i)
  323. {
  324. if (allInputs[i].className == "gadget_body popup" || allInputs[i].className == "gadget_body")
  325. {
  326. ButtonTable = document.createElement("table");
  327. ButtonTable.setAttribute("width", "100%");
  328.  
  329. var hrTR = document.createElement("tr");
  330. ButtonTable.appendChild(hrTR);
  331. var hrTD = document.createElement("td");
  332. hrTD.setAttribute("colspan", "2");
  333. hrTR.appendChild(hrTD);
  334. var hr = document.createElement("hr");
  335. hrTD.appendChild(hr);
  336.  
  337. var newTR = document.createElement("tr");
  338. ButtonTable.appendChild(newTR);
  339. var buttonTD = document.createElement("td");
  340. newTR.appendChild(buttonTD);
  341. newButton = document.createElement("input");
  342. newButton.setAttribute("type", "button");
  343. newButton.setAttribute("class", "button");
  344. newButton.setAttribute("value", ButtonText);
  345. newButton.addEventListener("click", ButtonFunct, false);
  346. buttonTD.appendChild(newButton);
  347. var checkTD = document.createElement("td");
  348. checkTD.setAttribute("width", "100%");
  349. checkTD.setAttribute("align", "left");
  350. newTR.appendChild(checkTD);
  351. for (var j = 0; j < CheckBoxes.length; ++j) {
  352. var checkbox = document.createElement("input");
  353. checkbox.addEventListener("click", UpdateSettings, false);
  354. checkbox.setAttribute("type", "checkbox");
  355. checkbox.setAttribute("id", LOCAL_VAR_NAME + CheckBoxes[j]);
  356. if (GM_getValue(LOCAL_VAR_NAME + CheckBoxes[j], true))
  357. checkbox.setAttribute("checked", "checked");
  358. checkTD.appendChild(checkbox);
  359.  
  360. var text = undefined;
  361. if (CheckBoxes[j] == "clr")
  362. text = Contents.Include_Color;
  363. else if (CheckBoxes[j] == "sz")
  364. text = Contents.Include_Size;
  365. else if (CheckBoxes[j] == "fnt")
  366. text = Contents.Include_Font;
  367. var label = document.createElement("label");
  368. label.setAttribute("for", LOCAL_VAR_NAME + CheckBoxes[j]);
  369. label.innerHTML = text.replace(" ", "&nbsp;") + "&nbsp;";
  370. checkTD.appendChild(label);
  371. }
  372.  
  373. allInputs[i].appendChild(ButtonTable);
  374. }
  375. }
  376. }
  377. return newButton;
  378. }
  379.  
  380. function GetLocalContents()
  381. {
  382. function GetLanguage()
  383. {
  384. var langText = null;
  385. var allMetas = document.getElementsByTagName("meta");
  386. for (var i = 0; i < allMetas.length; ++i)
  387. {
  388. if (allMetas[i].httpEquiv == "Content-Language")
  389. {
  390. langText = allMetas[i].content;
  391. break;
  392. }
  393. }
  394. return langText;
  395. }
  396.  
  397. var lang = GetLanguage();
  398. if (lang == null)
  399. return null;
  400.  
  401. if (Contents instanceof Object)
  402. {
  403. Contents = Contents[lang];
  404. return Contents;
  405. }
  406. else
  407. return null;
  408. }
  409.  
  410. //-----------------------------------------------------------------------------
  411. // "functionality" functions
  412. //-----------------------------------------------------------------------------
  413.  
  414. function UpdateSettings()
  415. {
  416. for (var i = 0; i < CheckBoxes.length; ++i) {
  417. GM_setValue(LOCAL_VAR_NAME + CheckBoxes[i], document.getElementById(LOCAL_VAR_NAME + CheckBoxes[i]).checked);
  418. }
  419. }
  420.  
  421. function CreateResult()
  422. {
  423. var newDiv = document.createElement("div");
  424. newDiv.setAttribute("class", "gadget_body");
  425. Result = document.createElement("textarea");
  426. Result.setAttribute("readonly", "true");
  427. Result.setAttribute("rows", 50);
  428. Result.setAttribute("cols", 110);
  429. Result.setAttribute("onmouseover", "attachResizer(this)");
  430. newDiv.appendChild(Result);
  431. MainContent.appendChild(newDiv);
  432. }
  433.  
  434. function OnCreateBB()
  435. {
  436. try {
  437. if (this.className == "button_disabled")
  438. return;
  439. else
  440. this.className = "button_disabled";
  441.  
  442. if (DefaultSize == undefined) {
  443. var span = document.createElement("span");
  444. span.setAttribute("class", "body");
  445. MainContent.appendChild(span);
  446. var styles = getFontProps(span);
  447. DefaultSize = styles.size;
  448. DefaultFont = styles.font;
  449. DefaultColor = styles.color;
  450. MainContent.removeChild(span);
  451. var link = document.createElement("a");
  452. link.setAttribute("href", "#");
  453. link.innerHTML = "test link";
  454. DefaultLinkColor = getLinkColor(getStyleCollection(link));
  455. }
  456. if (Result != undefined) {
  457. removeLastChild(Result.parentNode.parentNode.parentNode);
  458. }
  459. var ButtonParent = undefined;
  460. if (ButtonTable != undefined) {
  461. ButtonParent = ButtonTable.parentNode;
  462. ButtonParent.removeChild(ButtonTable);
  463. }
  464.  
  465. var hints = undefined;
  466. var hints_parent = undefined;
  467. var allInputs = document.getElementsByTagName("div");
  468. for (var i = 0; i < allInputs.length; ++i)
  469. {
  470. if (allInputs[i].className == "hints on" || allInputs[i].className == "hints off") {
  471. hints = allInputs[i];
  472. }
  473. }
  474. if (hints != undefined) {
  475. hints_parent = hints.parentNode;
  476. hints_parent.removeChild(hints);
  477. }
  478. var text = CreateBB(MainContent, "", "", "");
  479.  
  480. if (hints != undefined) {
  481. hints_parent.appendChild(hints);
  482. }
  483. if (ButtonParent != undefined) {
  484. ButtonParent.appendChild(ButtonTable);
  485. }
  486.  
  487. CreateResult();
  488. Result.innerHTML = "[url=http://userscripts.org/scripts/show/159281][size=9]" + Contents.Copyright + " v" + VER + "[/size][/url]\r\n" + text;
  489.  
  490. if (KeyButton.className == "button_disabled")
  491. KeyButton.className = "button";
  492. } catch (e) {
  493. alert("OnCreateBB(): " + e);
  494. }
  495. }
  496.  
  497. function GetName(name) {
  498. if (NameChange.hasOwnProperty(name)) {
  499. name = NameChange[name];
  500. }
  501. return name;
  502. }
  503.  
  504. function CreateBB(node, size, color, font) {
  505. var text = "";
  506. var addStart = "";
  507. var nodeName = node.nodeName.toLowerCase();
  508. var displayed = (NotDisplayed.indexOf(nodeName) == -1)
  509.  
  510. if (nodeName == "a") {
  511. var url = node.getAttribute("href");
  512. if (url != null) {
  513. url = url.replace(/\+/g, " ");
  514. url = url.removeLeft(location.protocol + "//" + location.host);
  515. var name = url.replace(/.*name=/g, "");
  516. name = decodeURIComponent(name.replace(/&.*/g, ""));
  517. if (name.startsWith("/wod/spiel/"))
  518. name = node.textContent.trim();
  519.  
  520. if (url.startsWith("http://world-of-dungeons.net/")) {
  521. url = url.removeLeft("http://world-of-dungeons.net/");
  522. var type = url.replace(/\/.*/g, "");
  523. name = url.replace(/.*\//g, "");
  524. name = decodeURIComponent(name.replace(/&.*/g, ""));
  525. if (type == "npc") url = "/wod/spiel/help/npc.php";
  526. else url = "/wod/spiel/hero/" + type + ".php";
  527. }
  528. if (url.startsWith("http://world-of-dungeons.org/")) {
  529. url = url.removeLeft("http://world-of-dungeons.org/");
  530. var type = url.replace(/\/.*/g, "");
  531. name = url.replace(/.*\//g, "");
  532. name = decodeURIComponent(name.replace(/&.*/g, ""));
  533. if (type == "npc") url = "/wod/spiel/help/npc.php";
  534. else url = "/wod/spiel/hero/" + type + ".php";
  535. }
  536.  
  537. for (var k = 0; k < SpecialURLs.length; ++k) {
  538. if (url.startsWith(SpecialURLs[k].url))
  539. return " [" + SpecialURLs[k].bbcode + ": \"" + name + "\"" + getLinkProps(node) + "] ";
  540. }
  541. if (url.startsWith("/wod/spiel/forum/viewforum.php") || url.startsWith("/wod/spiel/forum/viewtopic.php")) {
  542. var topic = url.startsWith("/wod/spiel/forum/viewtopic.php");
  543. var board = url.replace(/.*board=/g, "");
  544. board = board.replace(/&.*/g, "");
  545. var id = url.replace(/.*\.php\?(p)?id=/g, "");
  546. id = id.replace(/&.*/g, "");
  547. if (board == "gruppe" || board == "clan") {
  548. return " [" + (topic ? "pcom" : "forum") + ":ec_" + board + "_" + id + "|" + node.firstChild.textContent.trim() + "] ";
  549. } else if (board == "kein") {
  550. return " [" + (topic ? "post" : "forum") + ":" + id + "|" + node.firstChild.textContent.trim() + "] ";
  551. }
  552. }
  553.  
  554. addStart = "=" + encodeURI(node.getAttribute("href").removeLeft("http://"));
  555. } else {
  556. displayed = false;
  557. }
  558. } else if (nodeName == "img") {
  559. var src = node.getAttribute("src");
  560. var alt = node.getAttribute("alt");
  561. var height = node.getAttribute("height");
  562. var width = node.getAttribute("width");
  563. var align = node.getAttribute("align");
  564. var valign = node.getAttribute("valign");
  565. if (align == "bottom" || align == "top") align = null;
  566. if (valign == "left" || valign == "right") valign = null;
  567. if (src == null || IgnoredImages.indexOf(src) != -1)
  568. return "";
  569. if (src.startsWith("/wod/css/img/") && alt != null)
  570. return alt;
  571.  
  572. var skin = /http:\/\/skins.world-of-dungeons.net\/skins\/finals\/skin-[0-9]*\/images\/icons\/lang\//g;
  573. var diamond = /http:\/\/skins.world-of-dungeons.net\/skins\/finals\/skin-[0-9]*\/images\/icons\/diamond.gif/g;
  574. if (src.startsWith("/wod/css/icons/WOD/gems/") || src.match(skin) || src.match(diamond)) {
  575. src = src.substring(src.lastIndexOf("/") + 1);
  576. src = src.substring(0, src.lastIndexOf("."));
  577. if (src.startsWith("gem_")) src = src.replace("em_", "");
  578. if (src.startsWith("mgem_")) src = src.replace("gem_", "");
  579. return ":" + src + ":";
  580. }
  581. return "[img" + ((height != null && width != null) ? ("=" + width + "x" + height) : "") + (align != null ? (" align=" + align) : "") + (valign != null ? (" valign=" + valign) : "") + "]" + src + "[/img]";
  582. } else if (nodeName == "table") {
  583. var border = node.getAttribute("border");
  584. if (border != null)
  585. addStart = " border=" + border;
  586. if (node.getAttribute("class") == "content_table")
  587. addStart = " border=1";
  588. } else if (nodeName == "td") {
  589. var align = node.getAttribute("align");
  590. var valign = node.getAttribute("valign");
  591. var colspan = node.getAttribute("colspan");
  592. var rowspan = node.getAttribute("rowspan");
  593. if (valign == "baseline")
  594. valign = null;
  595.  
  596. if (align != null)
  597. addStart = " align=" + align;
  598. if (valign != null)
  599. addStart = " valign=" + valign;
  600. if (colspan != null)
  601. addStart = " colspan=" + colspan;
  602. if (rowspan != null)
  603. addStart = " rowspan=" + rowspan;
  604. } else if (nodeName=="option") {
  605. if(node.selected)
  606. return " " + node.textContent + " ";
  607. else
  608. return "";
  609. } else if (nodeName=="input") {
  610. var type = node.getAttribute("type");
  611. if (type=="checkbox" || type == "file" || type == "hidden" || type == "radio" || type == "password")
  612. return "";
  613.  
  614. var value = node.getAttribute("value");
  615. var url = node.getAttribute("url");
  616. if (value != null && value.trim().length > 0) {
  617. var text = "";
  618. var styles = getFontProps(node);
  619. if (styles.color != "") text += "[color=" + styles.color + "]";
  620. if (styles.size != "") text += "[size=" + styles.size + "]";
  621. if (styles.font != "") text += "[font=" + styles.font + "]";
  622.  
  623. text += " " + value.replace(/[\n\r]/g," ").replace(/\t|^[\t|\s]+|[\t|\s]+$/g, "") + " ";
  624.  
  625. if (styles.font != "") text += "[/font]";
  626. if (styles.size != "") text += "[/size]";
  627. if (styles.color != "") text += "[/color]";
  628. return text;
  629. }
  630. if (url != null && url.trim().length > 0) {
  631. return "[img]" + url + "[/img]";
  632. }
  633. return "";
  634. }
  635. if (Ignored.indexOf(nodeName) != -1) return text;
  636.  
  637. if (NewLineBefore.indexOf(nodeName) != -1)
  638. text += "\r\n";
  639. if (displayed) {
  640. text += (" [" + GetName(nodeName) + addStart + "]");
  641. }
  642.  
  643. var children = node.childNodes;
  644. if (children.length > 0) {
  645. var styles = getFontProps(node);
  646. for (var j = 0; j < children.length; ++j) {
  647. text += CreateBB(children[j], styles.size, styles.color, styles.font);
  648. }
  649. } else {
  650. if (node.textContent.trim().length > 0) {
  651. if (color != "") text += "[color=" + color + "]";
  652. if (size != "") text += "[size=" + size + "]";
  653. if (font != "") text += "[font=" + font + "]";
  654.  
  655. text += " " + node.textContent.replace(/[\n\r]/g," ").replace(/\t|^[\t|\s]+|[\t|\s]+$/g, "") + " ";
  656.  
  657. if (font != "") text += "[/font]";
  658. if (size != "") text += "[/size]";
  659. if (color != "") text += "[/color]";
  660. }
  661. }
  662.  
  663.  
  664. if (displayed && NoEnd.indexOf(nodeName) == -1) {
  665. text += ("[/" + GetName(nodeName) +"] ");
  666. }
  667.  
  668.  
  669. if (NewLineAfter.indexOf(nodeName) != -1)
  670. text += "\r\n";
  671.  
  672. return text;
  673. }
  674.  
  675. function getFontProps(node) {
  676. var styleCollection = getStyleCollection(node);
  677. return {color:getColor(styleCollection), size:getFontSize(styleCollection), font:getFont(styleCollection)};
  678. }
  679.  
  680. function getLinkProps(node) {
  681. var text = "";
  682.  
  683. if (node.childNodes.length > 0 && node.firstChild.nodeName.toLowerCase() != "#text")
  684. node = node.firstChild
  685. var styleCollection = getStyleCollection(node);
  686. var color = getLinkColor(styleCollection);
  687. var size = getFontSize(styleCollection);
  688. if (color != "") text += " color=" + color;
  689. if (size != "") text += " size=" + size;
  690. return text;
  691. }
  692.  
  693. function getLinkColor(styleCollection) {
  694. if (!GM_getValue(LOCAL_VAR_NAME + "clr", true)) return "";
  695. var txtColor = getItemColor(styleCollection);
  696. if (txtColor == DefaultLinkColor) txtColor = "";
  697. return txtColor;
  698. }
  699.  
  700. function getColor(styleCollection) {
  701. if (!GM_getValue(LOCAL_VAR_NAME + "clr", true)) return "";
  702. var txtColor = getItemColor(styleCollection);
  703. if (txtColor == DefaultColor) txtColor = "";
  704. return txtColor;
  705. }
  706.  
  707. function getItemColor(styleCollection) {
  708. if (styleCollection == undefined) return "";
  709. var txtColor = styleCollection.getStyle("color") // rgb(255,255,255);
  710. if (txtColor == undefined) return "";
  711. if (txtColor.startsWith("rgb(") && txtColor.endsWith(")")) {
  712. txtColor = txtColor.substring(4, txtColor.length - 1);
  713. var colors = txtColor.split(",");
  714. txtColor = "#" + toHex(colors[0]) + toHex(colors[1]) + toHex(colors[2]);
  715. }
  716. return txtColor;
  717. }
  718.  
  719. function getFontSize(styleCollection) {
  720. if (!GM_getValue(LOCAL_VAR_NAME + "sz", true) || styleCollection == undefined) return "";
  721.  
  722. var size = styleCollection.getStyle("font-size");
  723. if (size == undefined) size = "";
  724. size = size.removeRight("px");
  725. if (size == DefaultSize) size = "";
  726. return size;
  727. }
  728.  
  729. function getFont(styleCollection) {
  730. if (!GM_getValue(LOCAL_VAR_NAME + "fnt", true) || styleCollection == undefined) return "";
  731.  
  732. var family = styleCollection.getStyle("font-family");
  733. if (family == undefined) family = "";
  734. var comma = family.indexOf(',');
  735. if (comma != -1) family = family.substring(0, comma);
  736. if (family == DefaultFont) family = "";
  737. return family;
  738. }
  739.  
  740. function toHex(dec) {
  741. var ret = parseInt(dec, 10).toString(16);
  742. if (ret.length == 1) ret = "0" + ret;
  743. return ret;
  744. }
  745.  
  746. //-----------------------------------------------------------------------------
  747. // "main"
  748. //-----------------------------------------------------------------------------
  749. try {Main();} catch(e) {alert("Main(): " + e);}
  750.  
  751. })();
  752.