Created
January 20, 2023 04:31
-
-
Save lowteq/8d908ef7ebe284b2aeb6a9739693f529 to your computer and use it in GitHub Desktop.
tempermonkeyスクリプトでtwitter webのフォロー中タブをリロード時強制選択
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name auto click following tab | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description auto click following tab | |
// @author lowteq | |
// @match https://twitter.com/home | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=twitter.com | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
console.log("doInject tempermonkey"); | |
var target = document.querySelector('div[role="tablist"]'); | |
// div要素が存在しない場合は、1秒毎に再度取得を行う | |
if (!target) { | |
var observer = setInterval(function() { | |
target = document.querySelector('div[role="tablist"]'); | |
if (target) { | |
clearInterval(observer); | |
doInject(); | |
} | |
}, 1000); | |
} else { | |
doInject(); | |
} | |
// doInject関数 | |
function doInject() { | |
var followingTabButton = document.evaluate(`//div[@role='presentation']//span[text()='フォロー中']`, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; | |
var selected = document.evaluate(`//div[@role='presentation']//span[text()='フォロー中']/../../../../a`, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.getAttribute('aria-selected'); | |
console.log("doInject"); | |
if (selected =='false'){ | |
followingTabButton.click(); | |
console.log("clicked following tab"); | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment