Posted to tcl by ferrieux at Mon Apr 21 21:15:49 GMT 2008view raw

  1. // ==UserScript==
  2. // @name Platypus-groups.google.com/group/
  3. // @namespace Platypus
  4. // @include http://groups.google.com/group/comp.lang.tcl/topics?gvc=2// ==/UserScript==
  5. function do_platypus_script() {
  6. do_modify_html_it(window.document,document.evaluate('/HTML[1]/BODY[1]/TABLE[1]/TBODY[1]/TR[1]/TD[1]/DIV[3]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue,/.*(replica |gucci|wholesale|discount).*/gi,'',null);
  7. }; // Ends do_platypus_script
  8. window.addEventListener("load", function() { do_platypus_script() }, false);
  9. var gplatypusBundle = Components.classes["@mozilla.org/intl/stringbundle;1"].getService(Components.interfaces.nsIStringBundleService);
  10. var mystrings = gplatypusBundle.createBundle("chrome://platypus/locale/platypusCore.properties");
  11. var platypusplatypuscouldntfi1 = mystrings.GetStringFromName("platypusplatypuscouldntfi1");
  12. var platypusthisusuallyhappens = mystrings.GetStringFromName("platypusthisusuallyhappens");
  13.  
  14. //
  15. // Mon Dec 19 15:59:37 2005 -- Scott R. Turner
  16. // Short, uncommented file containing all the code to implement Platypus
  17. // actions. Can be "included" into the Platypus script.
  18. //
  19. //
  20. //
  21. function walk_down(node, func) {
  22. if (node.nodeType == 1) {
  23. if (node.tagName != "IMG") func(node);
  24. if (node.childNodes.length != 0)
  25. for (var i=0; i<node.childNodes.length; i++)
  26. walk_down(node.childNodes.item(i),func);
  27. }
  28. }
  29. function make_bw(doc, node) {
  30. walk_down(node,
  31. function (node) {
  32. if (node.tagName != 'A') {
  33. node.bgcolor = "white";
  34. node.color = "black";
  35. node.style.backgroundColor = "white";
  36. node.style.color = "black";
  37. node.style.backgroundImage = "";
  38. }});
  39. }
  40. function center_it(doc, node) {
  41. var center_node = doc.createElement ("CENTER");
  42. node.parentNode.insertBefore(center_node, node);
  43. node.parentNode.removeChild(node);
  44. center_node.appendChild(node);
  45. return center_node;
  46. };
  47. function erase_it(doc, node) {
  48. var offset_height = node.offsetHeight;
  49. var offset_width = node.offsetWidth;
  50. var replacement_div = doc.createElement ("DIV");
  51. replacement_div.setAttribute('style',
  52. "height: "+offset_height+"; width: "+offset_width+";");
  53. node.parentNode.insertBefore(replacement_div, node);
  54. node.style.display = "none";
  55. return replacement_div;
  56. };
  57. function smart_remove(doc, node) {
  58. if (node.parentNode.childNodes.length == 1) {
  59. smart_remove(doc, node.parentNode);
  60. } else {
  61. remove_it(doc, node);
  62. };
  63. };
  64. function remove_it(doc, node) {
  65. if (doc == null || node == null) return;
  66. if (!node.parentNode) return;
  67. node.style.display = "none";
  68. doc.last_removed_node = node;
  69. };
  70. function script_paste(doc, where, what) {
  71. var new_node = what.cloneNode(true);
  72. new_node.style.display = "";
  73. where.parentNode.insertBefore(new_node, where);
  74. };
  75. function isolate(doc, node) {
  76. if (!node.parentNode) return;
  77. node.parentNode.removeChild(node);
  78. while (doc.body.childNodes.length > 0) {
  79. doc.body.removeChild(doc.body.childNodes[0]);
  80. };
  81. var replacement_div = doc.createElement ("DIV");
  82. replacement_div.setAttribute('style',
  83. "margin: 0 2%; text-align: left");
  84. replacement_div.appendChild(node);
  85. doc.body.appendChild(replacement_div);
  86. };
  87. function set_style_script(doc, element, new_style) {
  88. element.setAttribute('style', new_style);
  89. };
  90. function modify_single_url(doc, match_re, replace_string, node) {
  91. if (node.href) {
  92. node.href = node.href.replace(match_re, replace_string);
  93. };
  94. };
  95. function do_modify_url_it(doc, node, match_re, replace_string, global_flag) {
  96. match_re = new RegExp(match_re);
  97. if (global_flag) {
  98. var allurls = doc.getElementsByTagName('A');
  99. for(var i = 0, url; url = allurls[i]; i++)
  100. modify_single_url(doc, match_re, replace_string, url);
  101. } else {
  102. modify_single_url(doc, match_re, replace_string, node);
  103. };
  104. };
  105. function do_modify_html_it(doc, element, match_re, replace_string) {
  106. match_re = new RegExp(match_re);
  107. if (element.innerHTML) {
  108. element.innerHTML = element.innerHTML.replace(match_re, replace_string);
  109. };
  110. };
  111. function relax(doc, node) {
  112. walk_down(node, function (node) {
  113. node.style.width = 'auto';
  114. node.style.marginLeft = '0pt';
  115. node.style.marginRight = '0pt';
  116. if (node.width) node.width = null; });
  117. }
  118. function fix_page_it(doc, node) {
  119. doc.background = null;
  120. doc.bgColor = "white";
  121. if (doc.style) {
  122. doc.style.backgroundColor = "white";
  123. doc.style.backgroundImage = "none";
  124. if (doc.style.color == "white") {
  125. doc.style.color = "black";
  126. };
  127. if (doc.text == "white") {
  128. doc.text = "black";
  129. };
  130. };
  131. doc.body.background = null;
  132. doc.body.bgColor = "white";
  133. if (doc.body.style) {
  134. doc.body.style.backgroundColor = "white";
  135. doc.body.style.backgroundImage = "none";
  136. if (doc.body.style.color == "white") {
  137. doc.body.style.color = "black";
  138. };
  139. if (doc.body.text == "white") {
  140. doc.body.text = "black";
  141. };
  142. };
  143. };
  144. function insertAfter(newNode, target) {
  145. var parent = target.parentNode;
  146. var refChild = target.nextSibling;
  147. if(refChild != null)
  148. parent.insertBefore(newNode, refChild);
  149. else
  150. parent.appendChild(newNode);
  151. };
  152. function html_insert_it(doc, element, new_html, before, insert_as_block) {
  153. var new_element;
  154. if (insert_as_block) {
  155. new_element = doc.createElement ("DIV");
  156. } else {
  157. new_element = doc.createElement ("SPAN");
  158. };
  159. new_element.innerHTML = new_html;
  160. if (before) {
  161. element.parentNode.insertBefore(new_element, element);
  162. } else {
  163. insertAfter(new_element, element);
  164. };
  165. };
  166. function auto_repair_it(doc, node) {
  167. var biggest_elem = find_biggest_elem(doc);
  168. isolate(doc, biggest_elem);
  169. relax(doc, biggest_elem);
  170. make_bw(doc, biggest_elem);
  171. fix_page_it(doc, biggest_elem);
  172. };
  173. function find_biggest_elem(doc) {
  174. const big_element_limit = 0.25;
  175. var size_of_doc = doc.documentElement.offsetHeight *
  176. doc.documentElement.offsetWidth;
  177. var body = doc.body;
  178. var size_of_body = body.offsetHeight * body.offsetWidth;
  179. if (size_of_body < (0.80 * size_of_doc)) {
  180. size_of_body = size_of_doc;
  181. };
  182. var max_size = 0;
  183. var max_elem = doc;
  184. var allElems = document.evaluate("//*",
  185. doc.body, null,
  186. XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
  187. null);
  188. for (var i = 0; i < allElems.snapshotLength; i++) {
  189. var thisElem = allElems.snapshotItem(i);
  190. var thisElem_size = thisElem.offsetHeight * thisElem.offsetWidth;
  191.  
  192. if (thisElem_size < size_of_body &&
  193. thisElem_size > max_size &&
  194. !contains_big_element(thisElem, size_of_body * big_element_limit)) {
  195. max_size = thisElem_size;
  196. max_elem = thisElem;
  197. };
  198. };
  199. return max_elem;
  200. };
  201.  
  202. function contains_big_element(node, limit) {
  203. if (node.childNodes.length != 0)
  204. for (var i=0; i<node.childNodes.length; i++) {
  205. var child = node.childNodes.item(i);
  206. var child_size = child.offsetHeight * child.offsetWidth;
  207. if (child_size > limit) return true;
  208. };
  209. return false;
  210. };
  211.  
  212. function platypus_do(win, func_name, o, other, other2, other3) {
  213. var func = eval(func_name);
  214. var doc = null;
  215. if (func == null) return;
  216. if (!o) {
  217. Warning(platypusplatypuscouldntfi1+
  218. func_name+platypusthisusuallyhappens);
  219. };
  220. doc = win.document;
  221. func(doc, o, other, other2, other3);
  222. };
  223.  
  224. //.user.js