AtCoder Twitter Avatar

Display Twitter avatar on AtCoder user page

目前為 2018-12-02 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         AtCoder Twitter Avatar
// @namespace    https://ciffelia.com/
// @version      1.0.1
// @description  Display Twitter avatar on AtCoder user page
// @author       prince <[email protected]> (https://ciffelia.com/)
// @license      MIT
// @homepage     https://github.com/prince0203/atcoder-twitter-avatar#readme
// @supportURL   https://github.com/prince0203/atcoder-twitter-avatar/issues
// @match        http*://atcoder.jp/user/*
// @match        https://beta.atcoder.jp/users/*
// @run-at       document-end
// ==/UserScript==

(function () {
  'use strict';

  const twLinkElm = document.querySelector('a[href*="//twitter.com/"]');

  if (twLinkElm !== null) {
    const screenName = twLinkElm.innerText;
    const avatarUrl = `https://avatars.io/twitter/${screenName}/small`;

    const avatarElm = document.createElement('img');
    avatarElm.src = avatarUrl;
    avatarElm.referrerPolicy = 'no-referrer';
    Object.assign(avatarElm.style, {
      width: '20px',
      height: '20px',
      marginRight: '5px',
      borderRadius: '50%'
    });

    twLinkElm.insertAdjacentElement('afterbegin', avatarElm);
  }

}());