Advertisement
Guest User

Untitled

a guest
Aug 4th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name       mmo-champ author sneak-peak
  3. // @namespace  
  4. // @version    0.1
  5. // @description  Hover recent threads to see author. I don't guarantee this works on anything other than Chrome and the current page structure of mmo-champion.
  6. // @match http://www.mmo-champion.com/content/*
  7. // @copyright  2016+, manhands
  8. // ==/UserScript==
  9.  
  10. var recentForumPostsIterator=document.evaluate("//h4[@class='cms_widget_post_header']/a[contains(@href, 'threads')]",document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);
  11. for (var i=0; i < recentForumPostsIterator.snapshotLength; i++) {
  12.     var thisA = recentForumPostsIterator.snapshotItem(i);
  13.     getAuthor(thisA);
  14. }
  15.  
  16. function getAuthor(thisA) {
  17.     var onSuccess = function(response, thisA) {
  18.         var re = /a class=".*?username.*?<strong>.*?<\/strong>/g;
  19.         var authorSegment = re.exec(response);
  20.         re = />[^<>]*?<\//g;
  21.         authorSegment = String(re.exec(authorSegment));
  22.         var subStart = 1;
  23.         var subStop = authorSegment.length-2;
  24.         authorSegment = authorSegment.substring(subStart,subStop);
  25.         thisA.title = authorSegment;
  26.     };
  27.     return grabAuthor(thisA, onSuccess);
  28. }
  29.  
  30. function grabAuthor(thisA, onSuccess) {
  31.     var xmlhttp = new XMLHttpRequest();
  32.     var link = thisA.href.substring(0, thisA.href.indexOf('?'));
  33.     xmlhttp.open("GET",link,true);
  34.     xmlhttp.onreadystatechange = function() {
  35.       if (xmlhttp.readyState==4 && xmlhttp.status==200)
  36.         onSuccess(xmlhttp.response, thisA);
  37.     };
  38.  
  39.     xmlhttp.send();
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement