Snippets

sironekotoro twitterの任意のリストをweb版twitterの上部に表示するuserscript

Created by sironekotoro
// ==UserScript==
// @name        twitterAddList
// @namespace   develop@sironekotoro.com
// @description twitterの任意のリストをweb版twitterの上部に表示するuserscript
// @include     https://twitter.com/*
// @version     1
// @grant       none
// ==/UserScript==
"use strict";
const d = document;

const urlList = [
    "https://twitter.com/sironekotoro/lists/perl",
    "https://twitter.com/sironekotoro/lists/stock",
    "https://twitter.com/sironekotoro/lists/ngfw"
];

// 読み込みが終わってから実行
window.onload = mainFunc(urlList);

function mainFunc(urlList) {

    // twitter Web版の上部にあるglobal-nav部に追加
    const ul = d.getElementById("global-actions");

    for (let i = 0; i < urlList.length; i++) {
        // リストのURLをa要素で囲む
        const a  = d.createElement("A");
        a.href   = urlList[i];

        // リストのURLを分解し、最後の要素をリスト名とする
        const splitUrlStr = urlList[i].split("/");
        const listName = (splitUrlStr[splitUrlStr.length-1]);
        a.textContent = listName;

        // li要素の中にa要素を入れる
        const li = d.createElement("LI");
        li.appendChild(a);

        // global-navのul要素の中にli要素を追加する
        ul.appendChild(li);
    }
}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.