eBay hide duplicate results updated

easy toggle to show or hide bunches of repeated results in eBay searches

  1. // ==UserScript==
  2. // @name eBay hide duplicate results updated
  3. // @description easy toggle to show or hide bunches of repeated results in eBay searches
  4. // @namespace kwhitefoot@hotmail.com
  5. // @include http://*search.ebay.tld/*
  6. // @include http://*shop.ebay.tld/*
  7. // @include http://*.ebay.tld/sch/*
  8. // @version 1.4
  9. // @grant GM_setValue
  10. // @grant GM_getValue
  11. // @run-at document-end
  12. // ==/UserScript==
  13.  
  14. /*
  15. Changes:
  16. =======
  17.  
  18. 1.1 Implemented a slightly more sophisticated matching algorithm:
  19. convert descriptions to lower case, if one description is
  20. contained in the other then they match. If they do not then split
  21. the descriptions into words and throw away duplicates if the
  22. resulting sets or words differ by less than 20% of the words then
  23. they match.
  24.  
  25. 1.2 Only operate on visible nodes. This helps us coexist properly
  26. with A Better Ebay Filter which sets display = 'none' to hide the
  27. filtered items.
  28.  
  29. 1.3 Cleaned up code.
  30.  
  31. 1.4 Implemented UI and internal changes necessary to allow the user to
  32. change the similarity threshold; the value is saved using
  33. GM_setValue. Made the selection of candidate items for hiding
  34. slightly more intelligent so that it should coexist even better
  35. with other scripts that also hide items. Removed support for old
  36. style pages.
  37. Changed includes to use tld as requested by Mikhoul.
  38.  
  39.  
  40. Description:
  41. ===========
  42.  
  43. This is a version of znerp's eBay hide duplicate results script from
  44. userscripts.org that works on http://www.ebay.com/sch/. I don't
  45. know if it still works on the other urls that are included or even
  46. if they still exist.
  47.  
  48. It has been extended to allow for almost identical descriptions to
  49. still count as a match and to report the number of duplicates next
  50. to the plus/minus icons.
  51.  
  52. In addition the user can specify how close the match must be for two
  53. items to count as the same.
  54.  
  55. There was no license specified on the original code so I assume that
  56. znerp meant to dedicate his version to the public domain. This
  57. version is therefore also dedicated to the public domain.
  58.  
  59. Authors:
  60. =======
  61.  
  62. kwhitefoot@hotmail.com
  63. znerp
  64.  
  65. Notes:
  66. =====
  67.  
  68. The file submitted to GreaseMonkey is the output of this command:
  69.  
  70. babel --watch=./src --out-dir=./build
  71.  
  72. The reason for this is that I am using Flow contract annotations for
  73. the variable and argument types and these must be removed before
  74. executing the script because Javascript will see them as syntax
  75. errors.
  76.  
  77. To do:
  78. =====
  79.  
  80.  
  81. */
  82.  
  83. // Use flow annotations. This is mostly just an exercise in the use
  84. // of flow rather than a serious use of them and it didn't uncover any
  85. // problems.
  86.  
  87. // Try to get early warning of poor code with use strict.
  88. 'use strict';
  89.  
  90. var MY_ATTRIBUTE = 'ebhdru'; // make sure there are no odd characters
  91. // in this.
  92. // Attribute for all elements that are added to items so that they can
  93. // be removed.
  94. var ITEM = MY_ATTRIBUTE + 'item';
  95.  
  96. // Tag to be used as a prefix for log messages. Then you can filter
  97. // the console log to see only our messages.
  98. var TAG = MY_ATTRIBUTE + ': ';
  99. var DEBUG = false;
  100. function dlog(msg) {
  101. if (DEBUG) {
  102. console.log(TAG + msg);
  103. }
  104. }
  105.  
  106. dlog('start');
  107.  
  108. // From http://stackoverflow.com/questions/15313418/javascript-assert,
  109. // by http://stackoverflow.com/users/2881350/karl-s
  110. if (typeof Error === "undefined") {
  111. Error = function (message) {
  112. this.message = message;
  113. };
  114. Error.prototype.message = "";
  115. }
  116.  
  117. function assert(condition, message) {
  118. if (!condition) {
  119. if (DEBUG) {
  120. alert(message || "Assertion failed");
  121. }
  122. throw new Error(message || "Assertion failed");
  123. }
  124. }
  125.  
  126. // Wrap the script in try..catch so that we can at least get a stack
  127. // trace in the console when something goes wrong.
  128. try {
  129. var plus = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAABnRSTlMA%2FwD%2FA" + "P83WBt9AAAAZElEQVR4nL2SUQ6AMAhDH2Q38v430DPhh4YsyHCLif0jK21hiJkBIgdvMNsAnWQ7TWCfYTtacKzl" + "70jp8yhn3lBguaH1RYjhZT%2FeNwdXurTTvf08tKP4xOXT0Poins5aBwhs4ATOOiHsGI5R2gAAAABJRU5ErkJgg" + "g%3D%3D";
  130. var minus = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAABnRSTlMA%2FwD%2F" + "AP83WBt9AAAACXBIWXMAAA7EAAAOxAGVKw4bAAAARklEQVR4nGP8%2F%2F8%2FAwMDIyMjAyEAUQmjiAMkKYYCh" + "Evw64a7mYlUG2ivAQHw%2BAFZimQbWIi0hHwb6BlKxAJSEx8T8XogygC6eSP5CxYWpwAAAABJRU5ErkJggg%3D%" + "3D";
  131.  
  132. // Element type names
  133. var INPUT = "INPUT";
  134. var SPAN = "SPAN";
  135. var BR = "BR";
  136. var DIV = "DIV";
  137. var BUTTON = "button";
  138. var BR = "BR";
  139.  
  140. //
  141. var changedText = "\u00a0 (Values changed.)";
  142.  
  143. // Descriptions that are more similar than this percentage are
  144. // regarded as identical and the second one will be hidden.
  145.  
  146. var matchThresholdName = 'matchThreshold';
  147. var matchThreshold = 80;
  148.  
  149. var CONTROL_ATTRIBUTE = MY_ATTRIBUTE + 'controlAttribute';
  150. function isCandidate(listItem) {
  151. //dlog('ha: ' + listItem.hasAttribute(CONTROL_ATTRIBUTE));
  152. //dlog('v: ' + listItem.style.visibility);
  153. //dlog('d: ' + listItem.style.display);
  154. dlog('isCandidate: ' + listItem.hasAttribute(CONTROL_ATTRIBUTE) + ' <' + listItem.style.visibility + '>' + ' <' + listItem.style.display + '>');
  155. return listItem.hasAttribute(CONTROL_ATTRIBUTE) || listItem.style.visibility !== 'hidden' && listItem.style.display !== 'none';
  156. }
  157.  
  158. function getCandidates() {
  159. dlog('getCandidates');
  160. var allResults = getAllItems();
  161. var candidates = [];
  162. for (var i = 0; i < allResults.snapshotLength; i++) {
  163. var thisResult = allResults.snapshotItem(i);
  164. //dlog('getCandidates a' + i);
  165. var thisHeading = thisResult.parentNode;
  166. var thisListItem = thisHeading.parentNode;
  167. if (isCandidate(thisListItem)) {
  168. //dlog('getCandidates got one');
  169. candidates.push(thisResult);
  170. }
  171. }
  172. dlog('getCandidates l: ' + candidates.length);
  173. return candidates;
  174. }
  175.  
  176. // From:
  177. // http://stackoverflow.com/questions/9496427/get-elements-by-attribute-when-queryselectorall-is-not-available-without-using-l
  178. // by: http://stackoverflow.com/users/629596/kevinfahy
  179. function getAllElementsWithAttribute(tagName, attribute) {
  180. var matchingElements = [];
  181. var allElements = document.getElementsByTagName(tagName);
  182. for (var i = 0, n = allElements.length; i < n; i++) {
  183. if (allElements[i].getAttribute(attribute) !== null) {
  184. // Element exists with attribute. Add to array.
  185. matchingElements.push(allElements[i]);
  186. }
  187. }
  188. return matchingElements;
  189. }
  190.  
  191. function type(obj) {
  192. return Object.prototype.toString.call(obj).match(/\s\w+/)[0].trim();
  193. }
  194.  
  195. function testType() {
  196. dlog('a: ' + type(""));
  197. dlog('b: ' + type(123));
  198. dlog('c: ' + type({}));
  199. dlog('e: ' + type(function () {}));
  200. }
  201.  
  202. function removeAddedItemElements() {
  203. var addedElements = document.querySelectorAll('[' + ITEM + ']');
  204. dlog('removeAddedItemElements: ' + type(addedElements));
  205. for (var i = 0; i < addedElements.length; i++) {
  206. var element = addedElements[i];
  207. element.parentElement.removeChild(element);
  208. }
  209. }
  210.  
  211. function removeToggleIcons() {
  212. // ebhdru: error: An invalid or illegal string was specified
  213.  
  214. // Looks like I'll just have to enumerate the elements the
  215. // slow way.
  216. dlog('removeToggleIcons');
  217. var icons = getAllElementsWithAttribute('image', TOGGLE_ICON);
  218. dlog('removeToggleIcons: ' + icons.length);
  219. icons.forEach(function (icon) {
  220. icon.parentElement.removeChild(icon);
  221. });
  222. }
  223.  
  224. // Compare each item description with the one that follows, if they
  225. // are very similar hide the second one. Attach a plus sign icon and
  226. // a count of duplicates to the first of the list; that is the one
  227. // that is not hidden. Attach a click event to it to toggle the
  228. // visibility.
  229.  
  230. // TODO: add icons and click events to hide individual items.
  231. function handleOtherPages() {
  232. dlog('handleOtherPages');
  233.  
  234. var allResults = getCandidates();
  235. assert(allResults, 'allResults must not be null');
  236. // Can't assert the length because GM executes this at times
  237. // when there are none. Perhaps we can detect that situation
  238. // and avoid getting this far.
  239.  
  240. if (allResults.length == 0) {
  241. return; // nothing to do
  242. }
  243. removeAddedItemElements();
  244.  
  245. dlog('handleOtherPages allResults: ' + allResults.length);
  246. var duplicateCount = 0;
  247. var icon;
  248. var iconNumber = 0;
  249. for (var i = 0; i < allResults.length - 1; i++) {
  250. //dlog('handleOtherPages: ' + i);
  251. var thisResult = allResults[i];
  252. var thisHeading = thisResult.parentNode;
  253. var thisListItem = thisHeading.parentNode;
  254. var nextResult = allResults[i + 1];
  255. var nextHeading = nextResult.parentNode;
  256. var nextListItem = nextHeading.parentNode;
  257. //dlog('thisHeading: ' + thisHeading.className);
  258. //dlog('thisListItem: ' + thisListItem.className);
  259. if (tokenMatch(thisResult.textContent, nextResult.textContent)) {
  260. if (duplicateCount == 0) {
  261. icon = addIcon(thisListItem, iconNumber);
  262. iconNumber++;
  263. }
  264. duplicateCount++;
  265. //dlog('hide dup i: ' + i);
  266. hideDuplicate(nextResult, duplicateCount);
  267. } else {
  268. if (hiddenByMe(nextListItem)) {
  269. nextListItem.style.display = "";
  270. }
  271. //dlog('duplicateCount: ' + duplicateCount);
  272. if (duplicateCount != 0) {
  273. var dups = createTextNode(duplicateCount + ' duplicates');
  274. icon.parentNode.insertBefore(dups, icon);
  275. duplicateCount = 0;
  276. icon = null;
  277. }
  278. }
  279. }
  280. }
  281.  
  282. function hiddenByMe(element) {
  283. assert(element.nodeName == 'LI', 'Expected a list item element');
  284. return element.hasAttribute(CONTROL_ATTRIBUTE);
  285. }
  286.  
  287. // Get all the items in the page.
  288. function getAllItems() {
  289. dlog('getAllItems');
  290. return document.evaluate('//a[contains(@class,"vip")]', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  291. }
  292.  
  293. var IS_CANDIDATE = MY_ATTRIBUTE + 'is candidate';
  294. // Add an attribute to indicate which items are candidates for
  295. // hiding etc. Only include those items that are visible so that
  296. // we work well with other scripts that also hide items.
  297. function prepareItems() {
  298. dlog('prepareItems');
  299.  
  300. var allResults = getAllItems();
  301. assert(allResults, 'allResults must not be null');
  302. var duplicateCount = 0;
  303. var icon;
  304. //var firstVisibleIndex: number = findFirstVisible(allResults)
  305. //var thisResult: object = allResults.snapshotItem(firstVisibleIndex)
  306. var iconNumber = 0;
  307. allResults.forEach(function (thisResult) {
  308. var thisHeading = thisResult.parentNode;
  309. var thisListItem = thisHeading.parentNode;
  310. if (thisListItem.style.display == 'show') {
  311. thisListItem.setAttribute(IS_CANDIDATE, "true");
  312. }
  313. });
  314. }
  315.  
  316. function findFirstVisible(allResults) {
  317. dlog('findFirstVisible');
  318. var i;
  319. for (i = 0; i < allResults.snapshotLength - 1; i++) {
  320. var thisResult = allResults.snapshotItem(i);
  321. var thisHeading = thisResult.parentNode;
  322. var thisListItem = thisHeading.parentNode;
  323. if (thisListItem.style.display = 'show') {
  324. dlog('findFirstVisible a: ' + i);
  325. return i;
  326. }
  327. }
  328. dlog('findFirstVisible b: ' + i);
  329. return i;
  330. }
  331.  
  332. function hideDuplicate(nextResult, duplicateCount) {
  333. dlog('hideDuplicate count:' + duplicateCount);
  334. var nextHeading = nextResult.parentNode;
  335. var nextListItem = nextHeading.parentNode;
  336. assert(nextListItem.nodeName == 'LI', 'Expected a list item element');
  337. nextListItem.style.display = "none";
  338. nextListItem.setAttribute(CONTROL_ATTRIBUTE, "hidden");
  339. nextHeading.appendChild(createTextNode(" <<duplicate " + duplicateCount + ">>"));
  340. }
  341.  
  342. // A slightly fuzzy match. At the moment it simply lops off the
  343. // first and last two characters and checks to see if what remains
  344. // is an exact match. The reason for ignoring the leading and
  345. // trailing characters is that vendors often add spurious
  346. // characters to distinguish otherwise identical descriptions.
  347. // Should be replaced with a more sophisticated measure which also
  348. // includes the price.
  349. function match(s1, s2) {
  350. //dlog('match ');
  351. //dlog('s1: ' + s1);
  352. //dlog('s2: ' + s2);
  353.  
  354. var a1 = s1.substring(2, s1.length - 2);
  355. var a2 = s2.substring(2, s2.length - 2);
  356. //dlog('a1: ' + a1);
  357. //dlog('a2: ' + a2);
  358.  
  359. return a1 == a2;
  360. }
  361.  
  362. // Find the uniques tokens in each description, if they differ by
  363. // fewer than some number then return true, else false.
  364. function tokenMatch(s1, s2) {
  365. //dlog('tokenMatch: <' + s1 +'> <' + s2 + '>');
  366. var lc1 = s1.toLowerCase();
  367. var lc2 = s2.toLowerCase();
  368. if (lc1 === lc2) {
  369. //dlog('tokenMatch matched lc');
  370. return true;
  371. }
  372. // If one description is wholly contained in another
  373. //dlog('tokenMatch a: <' + lc1 + '> <' + lc2 + '>');
  374. if (lc1.includes(lc2) || lc2.includes(lc1)) {
  375. //dlog('tokenMatch matched includes');
  376. return true;
  377. }
  378. // Get Sets of tokens
  379. //dlog('tokenMatch a1');
  380. var t1 = tokenise(lc1);
  381. //dlog('tokenMatch t1: ' + t1.size);
  382. var t2 = tokenise(lc2);
  383. //dlog('tokenMatch t2: ' + t2.size);
  384. var onlyIn1 = setDifference(t1, t2);
  385. //dlog('tokenMatch a4: ' + onlyIn1.size);
  386. var onlyIn2 = setDifference(t2, t1);
  387. //dlog('tokenMatch a5: ' + onlyIn2.size);
  388. if (onlyIn1.size == 0 || onlyIn2.size == 0) {
  389. // One set of tokens is a subset of the other or they are
  390. // identical.
  391. dlog('subset');
  392. return true;
  393. }
  394.  
  395. var len = Math.max(t1.size, t2.size);
  396. var differing = Math.max(onlyIn1.size, onlyIn2.size);
  397. var diff_fraction = differing / len;
  398. //dlog('tokenMatch c: ' + len + ' ' + differing + ' ' + diff_fraction);
  399. // If the number of distinct tokens in the largest set is ten then
  400. // allow two tokens difference.
  401. var max_allowed_diff = (1 - configuration.minimumSimilarity) * len;
  402. // If one description is wholly contained in another
  403. if (onlyIn1.size <= max_allowed_diff && onlyIn2.size <= max_allowed_diff) {
  404. //dlog('tokenMatch matched set diff');
  405. return true;
  406. }
  407. // Doesn't match.
  408. //dlog( 'no match');
  409. return false;
  410. }
  411.  
  412. // just trim and split on whitespace
  413. var whiteSpace = /\s+/g;
  414. function tokenise(s) {
  415. var tokens = s.trim().split(whiteSpace);
  416. tokens = s.trim().match(/\S+/g);
  417. var tokenSet = new Set(tokens);
  418. return tokenSet;
  419. }
  420.  
  421. // From
  422. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set.
  423. Set.prototype.intersection = function (setB) {
  424. var intersection = new Set();
  425. for (var elem of setB) {
  426. if (this.has(elem)) {
  427. intersection.add(elem);
  428. }
  429. }
  430. return intersection;
  431. };
  432.  
  433. function setDifference(setA, setB) {
  434. var diff = new Set(setA);
  435. for (var elem of setB) {
  436. diff.delete(elem);
  437. }
  438. return diff;
  439. }
  440.  
  441. var TOGGLE_ICON = MY_ATTRIBUTE + 'toggleIcon';
  442. // Add the plus icon to the beginning of the specified element and
  443. // attach a click event handler to reveal or hide the duplicates.
  444. function addIcon(thisListItem, iconNumber) {
  445. //dlog('addIcon: tagName: ' + thisListItem.tagName);
  446. var icon = createElement("img");
  447. icon.id = 'ebhdru' + iconNumber;
  448. icon.setAttribute(TOGGLE_ICON, TOGGLE_ICON);
  449. icon.src = plus;
  450. icon.setAttribute("style", "padding: 3px; cursor: pointer;");
  451. // Make sure that this item will not be accicetally hidden
  452. // later.
  453. thisListItem.removeAttribute(CONTROL_ATTRIBUTE);
  454. thisListItem.insertBefore(icon, thisListItem.firstChild);
  455. icon.addEventListener('click', function () {
  456. var listItem = this.parentNode;
  457. dlog('click: ');
  458. if (this.src == plus) {
  459. this.src = minus;
  460. showItems(listItem);
  461. } else {
  462. this.src = plus;
  463. hideItems(listItem);
  464. }
  465. }, true);
  466. return icon;
  467. }
  468.  
  469. function hideItems(listItem) {
  470. dlog('hideItems: tagName: ' + listItem.tagName);
  471. while (listItem = listItem.nextSibling) {
  472. dlog('hideItems: display: ' + listItem.style.display);
  473. dlog('hideItems: getAttribute: ' + listItem.getAttribute(CONTROL_ATTRIBUTE));
  474. if ("" == listItem.style.display) {
  475. if (listItem.getAttribute(CONTROL_ATTRIBUTE) == "shown") {
  476. listItem.setAttribute(CONTROL_ATTRIBUTE, "hidden");
  477. listItem.style.display = "none";
  478. } else {
  479. // Reached end of this hidden group
  480. return;
  481. }
  482. }
  483. }
  484. }
  485.  
  486. function showItems(listItem) {
  487. dlog('showItems: tagName: ' + listItem.tagName);
  488. while (listItem = listItem.nextSibling) {
  489. if (listItem.getAttribute(CONTROL_ATTRIBUTE) == "hidden") {
  490. listItem.style.display = "";
  491. listItem.setAttribute(CONTROL_ATTRIBUTE, "shown");
  492. } else {
  493. if (listItem.style.display == "") {
  494. // Item already visible so we have reached the end
  495. // of the group.
  496. return;
  497. }
  498. }
  499. }
  500. }
  501.  
  502. // function showItems(listItem: object) {
  503. // dlog('showItems: tagName: ' + listItem.tagName);
  504. // while((listItem = listItem.nextSibling).getAttribute(CONTROL_ATTRIBUTE) == "showing") {
  505. // listItem.style.display = "none"
  506. // listItem.setAttribute(CONTROL_ATTRIBUTE, "hidden")
  507. // }
  508. // }
  509.  
  510. var configuration = { minimumSimilarity: 0.8 };
  511.  
  512. function getConfiguration() {
  513. dlog('getConfiguration');
  514. for (var key in configuration) {
  515. configuration[key] = GM_getValue(key, configuration[key] + '') - 0;
  516. }
  517. }
  518.  
  519. function saveConfiguration() {
  520. dlog('saveConfiguration');
  521. for (var key in configuration) {
  522. dlog('k: ' + key + ' v: ' + configuration[key]);
  523. GM_setValue(key, configuration[key] + "");
  524. }
  525. }
  526.  
  527. function test() {
  528. var x = getAllItems();
  529. for (var i = 0; i < x.snapshotLength; i++) {
  530. var n = x.snapshotItem(i);
  531. dlog('nn: ' + n.nodeName);
  532. dlog('nt: ' + n.innerText);
  533. }
  534. }
  535.  
  536. // Copied from abef. Place our controls just below the related
  537. // searches div.
  538. function buildControls() {
  539. dlog('buildControls start');
  540. var divSibling = document.getElementById('RelatedSearchesDF');
  541. if (divSibling == null) {
  542. dlog('buildControls RelatedSearchesDF divSibling is null, try again.');
  543. divSibling = document.getElementById('TopPanelDF');
  544. }
  545. if (divSibling == null) {
  546. // This happens when GM executes the script a second time.
  547. // Just exit without doing anything.
  548. dlog('buildControls TopPanelDF divSibling is null, give up.');
  549. return false;
  550. }
  551.  
  552. dlog('buildControls add controls');
  553.  
  554. var newDivNode = document.createElement(DIV);
  555. newDivNode.title = "Ebay hide duplicate results";
  556.  
  557. var minimumSimilarityNode = document.createElement(INPUT);
  558. minimumSimilarityNode.type = "text";
  559. minimumSimilarityNode.size = 4;
  560. minimumSimilarityNode.style.textAlign = "right";
  561. minimumSimilarityNode.setAttribute("id", MY_ATTRIBUTE + 'minimumSimilarity');
  562. minimumSimilarityNode.defaultValue = 100 * configuration.minimumSimilarity;
  563.  
  564. var span1Node = document.createElement(SPAN);
  565. span1Node.style.fontWeight = "bold";
  566. span1Node.appendChild(minimumSimilarityNode);
  567. // Note: do not add MY_ATTRIBUTE to this node or it will be
  568. // deleted when we redo.
  569. span1Node.appendChild(document.createTextNode("% similarity threshold; hide items that are more similar than this."));
  570.  
  571. var applyNode = document.createElement(BUTTON);
  572. applyNode.appendChild(document.createTextNode("Apply"));
  573. applyNode.addEventListener('click', refresh, false);
  574.  
  575. newDivNode.appendChild(applyNode);
  576. newDivNode.appendChild(span1Node);
  577.  
  578. var parentNode = divSibling.parentNode;
  579. var nextSibling = divSibling.nextSibling;
  580. //parentNode.insertBefore(createElement(BR), nextSibling);
  581. //parentNode.insertBefore(createElement(BR), nextSibling);
  582. parentNode.insertBefore(newDivNode, nextSibling);
  583.  
  584. dlog('buildControls end');
  585. return true;
  586. }
  587.  
  588. function hideSimilarItems() {
  589. dlog('hideSimilarItems');
  590. handleOtherPages();
  591. }
  592.  
  593. function refresh(event) {
  594. dlog('refresh');
  595. if (event != null) {
  596. event.preventDefault();
  597. event.stopPropagation();
  598. }
  599. var minimumSimilarityNode = document.getElementById(MY_ATTRIBUTE + 'minimumSimilarity');
  600. var value = (minimumSimilarityNode.value - 0) / 100;
  601. configuration.minimumSimilarity = value;
  602. saveConfiguration();
  603.  
  604. dlog('msn: ' + value);
  605. hideSimilarItems();
  606. }
  607.  
  608. function addMyItemAttribute(node) {
  609. dlog('addMyItemAttribute: ' + type(node));
  610. node.setAttribute(ITEM, ITEM);
  611. }
  612.  
  613. // Add our identifying attribute to each node we create so that we
  614. // can easily delete them later. To do this we enclose the text
  615. // node in a span element. The reason for this is that we cannot
  616. // attach attributes to nodes so we would have difficulty finding
  617. // them later.
  618. function createTextNode(text) {
  619. dlog('createTextNode: ' + text);
  620. var span = createElement('span');
  621. span.innerText = text;
  622. return span;
  623. }
  624.  
  625. // Add our identifying attribute to each node we create so that we
  626. // can easily delete them later.
  627. function createElement(elementName) {
  628. var element = document.createElement(elementName);
  629. addMyItemAttribute(element);
  630. return element;
  631. }
  632.  
  633. function main() {
  634. dlog('main start');
  635. //test();
  636. getConfiguration();
  637. if (!buildControls()) {
  638. dlog('Giving up cannot find place to build controls.');
  639. return;
  640. }
  641. //prepareItems();
  642.  
  643. handleOtherPages();
  644.  
  645. dlog('main end');
  646. }
  647.  
  648. //estType();
  649. main();
  650. } catch (ex) {
  651. DEBUG = true;
  652. dlog("error: " + ex.message);
  653. dlog("stack: " + ex.stack);
  654. }
  655.  
  656. dlog('finish');