Greasy Fork 还支持 简体中文。

TweetOver PlainText Tooltip

Adds tweet text to a Twitter status link on mouse-over (title attribute) - EXPERIMENTAL - for LEGACY Greasemonkey

目前為 2017-10-15 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name TweetOver PlainText Tooltip
  3. // @description Adds tweet text to a Twitter status link on mouse-over (title attribute) - EXPERIMENTAL - for LEGACY Greasemonkey
  4. // @author Jefferson "jscher2000" Scher
  5. // @namespace JeffersonScher
  6. // @copyright Copyright 2017 Jefferson Scher
  7. // @license MIT
  8. // @include http*://*
  9. // @version 0.1
  10. // @grant GM_xmlhttpRequest
  11. // ==/UserScript==
  12.  
  13. // Retrieve tweet details for each status link found
  14. function TOPT_findLinks(tgt){
  15. // TODO - PROBABLY NOT THE IDEAL METHOD OF IDENTIFYING THESE LINKS
  16. var tweets = tgt.querySelectorAll('a[href^="https://twitter.com/"][href*="/status/"]');
  17. for (var i=0; i<tweets.length; i++){
  18. // TODO - VERIFY LINK VALIDITY
  19. TOPT_addTitle(tweets[i]);
  20. }
  21. }
  22.  
  23. // Use GM's cross-site XHR function to get the tweet
  24. function TOPT_addTitle(ael){
  25. // TODO: HANDLE RESPONSE ERRORS
  26. GM_xmlhttpRequest({
  27. method: "GET",
  28. url: "https://publish.twitter.com/oembed?url=" + ael.href,
  29. headers: {
  30. "Accept": "text/json"
  31. },
  32. onload: function(response) {
  33. var tweet = JSON.parse(response.responseText);
  34. var dTweet = document.createElement("div");
  35. dTweet.innerHTML = tweet.html; /* Could do "rich" overlay, but this script doesn't */
  36. var tweetText = dTweet.querySelector('blockquote').textContent;
  37. ael.setAttribute("title", tweetText);
  38. }
  39. });
  40. }
  41.  
  42. // Check for Twitter links 1.5 seconds after DOM Content Loaded
  43. window.setTimeout(function(){TOPT_findLinks(document.body);}, 1500);