LoginSignup
4
2

More than 5 years have passed since last update.

Qiitaの通知一覧から、いいねしてくれたユーザーのページに直リンするUserscriptを作った 非jQuery版

Posted at

Qiitaの通知一覧から、いいねしてくれたユーザーのページに直リンするUserscriptを作った - Qiita

:oncoming_police_car:Qiita警察だ!!:oncoming_police_car:

とっても便利な機能!なのですが、一身上の都合によりネイティブで使いたいため書き換えさせてもらいます。

動作検証環境

  • Firefox 61.0
  • Tampermonkey 4.7.5788

コード

qiita-user-link.user.js
// ==UserScript==
// @name         Qiita user link
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Qiitaの通知欄から直接ユーザページに遷移できるようにする。
// @author       khsk
// @match        https://qiita.com/notifications*
// @grant        none
// ==/UserScript==

// https://qiita.com/Sinhalite/items/892d4c972aeed6d1dcaf

(function() {
    'use strict';

    // queryをspan.bold:first-child指定にしてtextContentがツイートを弾くでもよさそう
    document.querySelectorAll('.notification_actionWrapper > span:first-child').forEach((node) => {
        // nextSiblingではテキストノードの「が」が引っかかるのでElementを
        if (node.nextElementSibling.textContent == 'ツイート') {
            return;
        }
        const link = document.createElement('a');
        link.href = node.textContent;
        link.target = '_parent';
        link.appendChild(node.cloneNode(true));
        node.parentNode.replaceChild(link, node);
    });
})();

next(Element)Siblingなんておそらく初めて使いました。
勉強になりますねー


見やすく短いのはjQueryでしょうかー
便利ですねー


こういう場合にauthor書き換えるべきか少し悩みます。

4
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2