Advertisement
Kartom

GayRomeo VisitorCheck 0.3.2 (aug 2013)

Aug 10th, 2013
437
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name           GayRomeo_VisitorCheck
  3. // @namespace      http://userscripts.org/scripts/versions/30322
  4. // @description    Periodically checks for new visitors on your profile
  5. //
  6. // @match        *://*.gayromeo.com/*main/shortcuts.php
  7. // @match        *://*.planetromeo.com/*main/shortcuts.php
  8. // @match        *://83.98.143.20/*main/shortcuts.php
  9. //
  10. // @version        0.3.2
  11. //
  12. // ==/UserScript==
  13. //
  14. // History
  15. //
  16. // 3.2      ( 2013-Aug-11 ) -Djamana-
  17. //
  18. // [*] Update @match'es
  19. // [*] StatusReset on Mouseover
  20. // [*] Code design changes
  21.  
  22.  
  23.  
  24. var checkInterval                   = 30 * 1000; // msec
  25. var visitorLinkDivHighlightStyle    = "background:#800000";
  26. var MY_VISITORS                     = "Meine Besucher"
  27. var link_SearchMyVisitors           = "/search/index.php?action=execute&searchType=myVisitors";
  28.  
  29. var visitorLinkDiv  = null;
  30. var visitorPageLink = location.protocol + "//" + location.host + link_SearchMyVisitors;
  31. var lastVisitor     = null;
  32. var lastTaps        = null;
  33. var lastTapsDiv     = null;
  34.  
  35. /////////////////////////////////////////////////////////////////////
  36. //
  37. //              F u n c t i o n s
  38. //
  39.  
  40. function resetVisitorColor() {
  41.     visitorLinkDiv.setAttribute("style", "");
  42. }
  43.  
  44. function setVisitorColor() {
  45.     visitorLinkDiv.setAttribute("style", visitorLinkDivHighlightStyle);
  46. }
  47.  
  48. function checkLastVisitor() {
  49.  
  50.     var req = new XMLHttpRequest();
  51.  
  52.     req.open('GET', link_SearchMyVisitors, true);
  53.     req.onreadystatechange = function (aEvt) {
  54.         if (req.readyState == 4 && req.status == 200) {
  55.  
  56.  
  57.             var doc = evaluateResponse( req.responseText );
  58.  
  59.             updateVistitorNTaps( doc );
  60.  
  61.         }
  62.     };
  63.     req.send(null);
  64. }
  65.  
  66. function evaluateResponse(docText) {
  67.  
  68.  
  69.     function getBody(content)
  70.     {
  71.         var x = content.indexOf("<body");
  72.             x = content.indexOf(">", x);
  73.  
  74.         var y = content.lastIndexOf("</body>");
  75.  
  76.         return content.slice( x + 1, y );
  77.     }
  78.  
  79.  
  80.     var doc = document.createElement("body")
  81.         doc.innerHTML = getBody(docText)
  82.     return doc
  83.  
  84. }
  85.  
  86. function updateVistitorNTaps( doc) {
  87.  
  88.     checkVisitor(doc);
  89.     checkTaps(doc);
  90. }
  91.  
  92.  
  93. function xEval( doc, xpath ) {
  94.  
  95.     var tmp = document.evaluate(
  96.             xpath,
  97.             doc,
  98.             null,
  99.             XPathResult.FIRST_ORDERED_NODE_TYPE,
  100.             null )
  101.  
  102.     return  tmp.singleNodeValue
  103. }
  104.  
  105.  
  106. function checkVisitor(doc) {
  107.  
  108.     var list = xEval( doc,
  109.         "//td[@class='resHeadline']/a"
  110.     );
  111.  
  112.     if (list) {
  113.  
  114.         // Any new visitors ?
  115.         var currentLastVisitor = list.firstChild.nodeValue;
  116.         var IsNewVistors =  ( lastVisitor != currentLastVisitor)
  117.         var IsInitialCall =  !lastVisitor
  118.  
  119.         if (  IsNewVistors && !(IsInitialCall)  ) {
  120.             // Yes - so set status
  121.             setVisitorColor();
  122.         }
  123.  
  124.         // Show/Update Taps data for new visitor
  125.         if (  IsNewVistors  ||  (IsInitialCall)  ) {
  126.  
  127.             if (visitorName.hasChildNodes()) {
  128.                 visitorName.removeChild( visitorName.firstChild);
  129.             }
  130.  
  131.             visitorName.appendChild( list);
  132.         }
  133.  
  134.         // Update Done - so set last visitor <= current visitor;
  135.         lastVisitor = currentLastVisitor;
  136.  
  137.  
  138.     }
  139. }
  140.  
  141.  
  142.  
  143. function checkTaps(doc) {
  144.  
  145.     var tapsImg = xEval( doc,
  146.         "//td[@colspan='5']"  );
  147.  
  148.      tapsImg = xEval( tapsImg,
  149.         "img[contains(@src,'/footprints/')]"    );
  150.  
  151.     var oldTaps = lastTapsDiv.firstChild;
  152.  
  153.     var hasTaps =  !!oldTaps
  154.  
  155.     if (tapsImg) {
  156.  
  157.         var isSameTaps = (tapsImg.src == lastTaps)//.title.split(" ")[0] == lastVisitor)
  158.         if (!isSameTaps) {
  159.  
  160.             if (hasTaps)
  161.                 lastTapsDiv.removeChild(oldTaps);
  162.  
  163.             lastTapsDiv.appendChild(tapsImg);
  164.             tapsImg.removeAttribute("align");
  165.  
  166.         }
  167.  
  168.         lastTaps = tapsImg.src
  169.  
  170.     } else
  171.  
  172.         lastTaps = null
  173.  
  174.  
  175.     if ( ( hasTaps ) && !isSameTaps) {
  176.         lastTapsDiv.removeChild(oldTaps);
  177.     }
  178.  
  179.  
  180. }
  181.  
  182.  
  183.  
  184. /////////////////////////////////////////////////////////////////////
  185. //
  186. //                          M a i n
  187. //
  188.  
  189. // Normally all short elements have the class 'rowLine'
  190. // Expect the last the last that has 'row'...
  191.  
  192.  
  193. var lastRowDiv = xEval( document,
  194.             "\
  195.            //div[@class='list_back'][last()] \
  196.             /div[@class='content'] \
  197.             /div[@class='row'] \
  198.            ");
  199.  
  200. // ... so overwrite the class of last element to 'rowLine' ...
  201.     lastRowDiv.setAttribute("class", "rowLine");
  202.  
  203. // select last .shortcuts div.content
  204. var contentDiv = lastRowDiv.parentNode
  205.  
  206.  
  207.     // ------ div Visitors-------
  208. // ... and add a new div with class 'row'.
  209.         visitorLinkDiv = document.createElement( "div" );
  210.         visitorLinkDiv.setAttribute("class", "row"              );
  211.         visitorLinkDiv.setAttribute("title", MY_VISITORS    );
  212.     contentDiv.appendChild(visitorLinkDiv);
  213.  
  214.     // ------ div Visitors   -------
  215.     // ------ a 'myVisitors' -------
  216.  
  217.     var myVisitorLink = document.createElement( "a" );
  218.         myVisitorLink.setAttribute( "style",    "color: rgb(255, 153, 0);"  );
  219.         myVisitorLink.setAttribute( "accesskey", "b"                        );
  220.         myVisitorLink.setAttribute( "target",   "mitte"                     );
  221.         myVisitorLink.setAttribute("href", link_SearchMyVisitors);
  222.         myVisitorLink.appendChild( document.createTextNode( MY_VISITORS ) );
  223.  
  224.  
  225.     visitorLinkDiv.appendChild( myVisitorLink);
  226.     visitorLinkDiv.addEventListener("click", resetVisitorColor, false);
  227.     visitorLinkDiv.addEventListener("mouseover", resetVisitorColor, false);
  228.  
  229.     // ------ div Taps   -------
  230.     // ------ >> ----------------
  231.  
  232.     var lastVisitorDiv = document.createElement("div");
  233.         visitorLinkDiv.appendChild(lastVisitorDiv);
  234.  
  235.     // >>
  236.     lastVisitorDiv.appendChild(document.createTextNode("\u00A0\u00bb "));
  237.  
  238.  
  239.         visitorName = document.createElement("span");
  240.         lastVisitorDiv.appendChild(visitorName);
  241.         visitorName.appendChild(document.createTextNode("..."));
  242.  
  243.         lastTapsDiv = document.createElement("div");
  244.         lastTapsDiv.setAttribute("style", "width:100%;text-align:center")
  245.         lastTapsDiv.appendChild(document.createTextNode(""));
  246.  
  247.     lastVisitorDiv.appendChild(lastTapsDiv);
  248.  
  249.  
  250.     // Install timer
  251.     setInterval( checkLastVisitor, checkInterval);
  252.  
  253.     // initial Call to Update LastVisitor (So we don't need to wait for timer)
  254.     checkLastVisitor();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement