Tampermonkeyスクリプト
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
開始行:
* Twitterの検索結果から表示名にキーワードを含んでくる奴と...
** はじめに [#qbf39ce4]
- Twitterで完全一致検索が出来ないのは以下ツイートでもある...
-- https://twitter.com/thisiskogatti/status/2028742150175...
<pre>
明らか脆弱性か何かを突いてそうなやり方なんですが、「”」じ...
</pre>
- 元々の検索結果がカス過ぎると、すぐにレートリミットに達...
上記方法での完全結果検索も活かして検索するように心がけて...
** コード本体 [#b8300c77]
<pre>
// ==UserScript==
// @name Twitter Search Query Filter
// @namespace https://junkyard.shirotsume.ch/
// @version 1.0.1a
// @description Twitter検索結果からユーザーの表示名に検...
// @author shirotsume
// @match https://x.com/search*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// 検索ワードを取得する関数
function getSearchQuery() {
const urlParams = new URLSearchParams(window.loca...
return urlParams.get("q") || "";
}
// 検索結果を監視し、条件を満たす要素を非表示にする
function filterSearchResults() {
const query = getSearchQuery();
if (!query) return;
const searchWords = query
.split(/\s+/)
.map(word => word.replace(/%22/g, '')) // %22...
.map(word => word.replace(/^[^\p{L}\p{N}]+|[^...
.filter(word => word.length > 0); // 除去後に...
// 検索結果のリストを取得
const results = document.querySelectorAll("articl...
results.forEach(result => {
const tweetTextElement = result.querySelector...
if (tweetTextElement) {
const tweetText = tweetTextElement.textCo...
// ツイート本文に検索ワードが含まれている...
// someならOR、everyならAND。ANDにしてし...
if (!searchWords.some(word => tweetText.t...
result.style.display = "none";
}
} else {
result.style.display = "none";
}
});
}
// URL変化の検知
let lastUrl = location.href;
function onUrlChange() {
const currentUrl = location.href;
if (currentUrl !== lastUrl) {
lastUrl = currentUrl;
// URL変化後、DOMの描画を少し待ってからフィル...
setTimeout(filterSearchResults, 500);
}
}
const observer = new MutationObserver(() => {
onUrlChange();
filterSearchResults();
});
observer.observe(document.body, {
childList: true,
subtree: true
});
filterSearchResults();
})();
</pre>
終了行:
* Twitterの検索結果から表示名にキーワードを含んでくる奴と...
** はじめに [#qbf39ce4]
- Twitterで完全一致検索が出来ないのは以下ツイートでもある...
-- https://twitter.com/thisiskogatti/status/2028742150175...
<pre>
明らか脆弱性か何かを突いてそうなやり方なんですが、「”」じ...
</pre>
- 元々の検索結果がカス過ぎると、すぐにレートリミットに達...
上記方法での完全結果検索も活かして検索するように心がけて...
** コード本体 [#b8300c77]
<pre>
// ==UserScript==
// @name Twitter Search Query Filter
// @namespace https://junkyard.shirotsume.ch/
// @version 1.0.1a
// @description Twitter検索結果からユーザーの表示名に検...
// @author shirotsume
// @match https://x.com/search*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// 検索ワードを取得する関数
function getSearchQuery() {
const urlParams = new URLSearchParams(window.loca...
return urlParams.get("q") || "";
}
// 検索結果を監視し、条件を満たす要素を非表示にする
function filterSearchResults() {
const query = getSearchQuery();
if (!query) return;
const searchWords = query
.split(/\s+/)
.map(word => word.replace(/%22/g, '')) // %22...
.map(word => word.replace(/^[^\p{L}\p{N}]+|[^...
.filter(word => word.length > 0); // 除去後に...
// 検索結果のリストを取得
const results = document.querySelectorAll("articl...
results.forEach(result => {
const tweetTextElement = result.querySelector...
if (tweetTextElement) {
const tweetText = tweetTextElement.textCo...
// ツイート本文に検索ワードが含まれている...
// someならOR、everyならAND。ANDにしてし...
if (!searchWords.some(word => tweetText.t...
result.style.display = "none";
}
} else {
result.style.display = "none";
}
});
}
// URL変化の検知
let lastUrl = location.href;
function onUrlChange() {
const currentUrl = location.href;
if (currentUrl !== lastUrl) {
lastUrl = currentUrl;
// URL変化後、DOMの描画を少し待ってからフィル...
setTimeout(filterSearchResults, 500);
}
}
const observer = new MutationObserver(() => {
onUrlChange();
filterSearchResults();
});
observer.observe(document.body, {
childList: true,
subtree: true
});
filterSearchResults();
})();
</pre>
ページ名:
This site is protected by
Turnstile
and the Cloudflare
Privacy Policy
and
Terms of Service
apply.