generated at
Twitterで短い名前の人のツイートをGyazoったときの検索性を高めるUserScript

ここにユーザー名入れるUserScript

必要

Twitterで画像をGyazoったときGyazoで名前で検索できなくて困る
一文字だけの人
例:あさんはTwitterを使っています
Gyazoの本文が nameさんはTwitterを使っています になる
たぶん document.title を取得しているから
数字や記号だけの人
例:12さんはTwitterを使っています
ab さんは検索できない。何故か全て出る
twitter.com/ab のようなドメイン検索もきかない

どうする
screen name(@aaaみたいなやつ)も入れる
Twitterは短いnameを取るのはもう無理なので、検索できる可能性が上がる
完全に検索できるわけではない

TwitterのURLを開いたときにdocument.titleにscreen nameを入れるUserScriptを書いて対応する
js
// ==UserScript== // @name Add screen name to title for Gyazo // @namespace http://tampermonkey.net/ // @version 0.2 // @description Search tweet by screen name // @author motoso // @match https://twitter.com/* // @icon https://www.google.com/s2/favicons?domain=twitter.com // @grant none // ==/UserScript== (function () { 'use strict'; // https://stackoverflow.com/questions/62121185/js-window-onload-why-dont-wait-loaded const observer = new MutationObserver(mutations => { if (mutations.some(mutation => { return Array.from(mutation.addedNodes).some(node => node.querySelector('article')) })) { setTimeout(() => { // Wait for all the updates of this frame to go through // ページを表示したときにタイトルを変える console.log('Page fully loaded!') const url = window.location.href; const name = url.match(/https:\/\/twitter.com\/([\S]+)\/status/)[1]; const title = document.title; document.title = `@${name} ${title}`; // 画像クリックしたときにタイトルを変える let img_elements = document.querySelectorAll("a"); for (var i = 0; i < img_elements.length; i++) { // 画像読み込み完了したときの処理 img_elements[i].addEventListener('click', (e) => { setTimeout(() => { console.log(e.target.alt + " click"); const url = window.location.href; const name = url.match(/https:\/\/twitter.com\/([\S]+)\/status/)[1]; const title = document.title; document.title = `@${name} ${title}`; }, 1) // ここを0にすると、ロード後になぜか少し待たないとタイトルが変更されない。なぜ? }); } }, 0) observer.disconnect() } }) observer.observe(document, { attributes: false, childList: true, characterData: false, subtree: true }) })();

実現できていないこと
タイムラインから直接飛ぶと動かない
一度別タブでひらく必要がある
複数画像があったときにスライドしたときタイトルが元に戻ってしまう
どうも毎回titleを書き換える処理がはしっているらしい
なんかのイベントに引っ掛けて名前を戻せるだろうか?
画像を閉じるタイミングでタイトル元に戻ってしまう
どうも毎回titleを書き換える処理がはしっているらしい