Twitter

If you hate Twitter t.co URL shortener and would like to see the full links in your timeline, this is the script for you.

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

You will need to install an extension such as Tampermonkey to install this script.

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name           Twitter
// @namespace      http://fcmartins.net
// @include        http://twitter.com/*
// @include        https://twitter.com/*
// @version 0.0.1.20180906145405
// @description If you hate Twitter t.co URL shortener and would like to see the full links in your timeline, this is the script for you.
// ==/UserScript==

function httpExpandURI(element) {
  GM_xmlhttpRequest({
    url: element.getAttribute("data-expanded-url"),
    method: "HEAD",
    onload: function(response) {
      modify(element, response.finalUrl);
    }
  });
}

function modify(element, url) {
  element.setAttribute("href", url);
  element.textContent = url;
  
  element.removeAttribute("data-ultimate-url");
  element.removeAttribute("title");
  element.removeAttribute("data-expanded-url");
  docHeight = document.getElementById("stream-items-id").scrollHeight;
}

function expandURL() {
  Array.forEach(document.getElementsByTagName("a"), function(element, index, array) {
    if(element.className.indexOf("twitter-timeline-link") != -1 && element.getAttribute("data-expanded-url")) {
      if(element.getAttribute("data-ultimate-url")) {
        modify(element, element.getAttribute("data-ultimate-url"));        
      }
      else {
        httpExpandURI(element);
      }      
    }
  });    
}

function divClick() {
  window.setTimeout(expandURL, 1000);
}

function newTweetsBar() {
  var div = document.getElementsByClassName("new-tweets-bar")[0];
  if(typeof div !== "undefined") {
    div.addEventListener("click", divClick, false);
  }
}

function onScroll(e) {
  if(scrollId) {
    window.clearTimeout(scrollId);
  }
  scrollId = window.setTimeout(function() {
    if(docHeight < document.getElementById("stream-items-id").scrollHeight) {
      expandURL();      
    }
  }, 2000);
}

function start() {
  if(document.getElementById("stream-items-id")) {
    window.clearTimeout(startId);
    docHeight = document.getElementById("stream-items-id").scrollHeight;
    expandURL();
  }
}

var scrollId;
var docHeight;
var startId;

window.addEventListener("load", function(e) {
  startId = window.setInterval(start, 1000);
}, false);
window.setInterval(newTweetsBar, 1000);
window.addEventListener("scroll", onScroll, false);