Skip to content

Instantly share code, notes, and snippets.

@Eniwder
Last active August 2, 2019 10:04
Show Gist options
  • Select an option

  • Save Eniwder/91e3ca4a917c5b8992ffb51d22b2a383 to your computer and use it in GitHub Desktop.

Select an option

Save Eniwder/91e3ca4a917c5b8992ffb51d22b2a383 to your computer and use it in GitHub Desktop.
ツイートをクリックした時にページ遷移させないuserScript
// ==UserScript==
// @name Twitter使いやすく
// @version 1.11
// @grant none
// @include https://twitter.com/*
// ==/UserScript==
// ツイートクリック時にユーザーページに飛ぶのを防ぐ
const currentPath = '/'+document.location.href.match(/twitter.com\/(.*)/)[1];
const tweetClicked = e => {
// 'data-permalink-path'の値が現在のアドレスと同じ時は遷移しないようなので、そう設定
const elem = e.originalTarget;
const permalink = elem.getAttribute('dpp') || elem.getAttribute('data-permalink-path');
if(!permalink) return;
elem.setAttribute('data-permalink-path',currentPath);
elem.setAttribute('dpp',permalink);
// z-indexは検索時のフィルタ条件が999
const overlay =
`<div id="dppOl" style="z-index: 1000;opacity: 0.7;background-color: black;width: 100%;height: 100%;position: fixed;top: 0;left: 0;" onclick="(function(){
document.querySelector('#inlinePermalink').remove();
document.querySelector('#dppOl').remove();
})()"></div>`;
document.body.insertAdjacentHTML('afterbegin', overlay);
const iframe =
`<iframe id="inlinePermalink" src="${permalink}" style="position: fixed;top: 80px;left: 0;right: 0;margin: auto;width: 680px;height:80%;z-index:1001;overflow-y:hidden;"></iframe>`;
document.body.insertAdjacentHTML('afterbegin', iframe);
}
let tl = -1;
setInterval(() => {
const tweets = document.querySelectorAll('.tweet');
if(tl === tweets.length) return;
tl = tweets.length;
tweets.forEach(tweet => {
tweet.removeEventListener("click", tweetClicked);
tweet.addEventListener('click',tweetClicked)
});
},500);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment