Skip to content

Instantly share code, notes, and snippets.

@lowteq
Created January 20, 2023 04:31
Show Gist options
  • Save lowteq/8d908ef7ebe284b2aeb6a9739693f529 to your computer and use it in GitHub Desktop.
Save lowteq/8d908ef7ebe284b2aeb6a9739693f529 to your computer and use it in GitHub Desktop.
tempermonkeyスクリプトでtwitter webのフォロー中タブをリロード時強制選択
// ==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