Add favicon to pinboard

Add favicon to pinboard bookmarks

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Add favicon to pinboard
// @namespace    http://tampermonkey.net/
// @version      0.1.2
// @description  Add favicon to pinboard bookmarks
// @author       yueyericardo
// @match        https://pinboard.in/u:*
// @icon         https://www.google.com/s2/favicons?domain=pinboard.in
// @grant        GM_addStyle
// @run-at       document-end
// ==/UserScript==

GM_addStyle(`
/* icon */
.star {
    width: 36px;
    cursor: auto;
}
.star span{
    cursor: pointer;
}
.star img{
    width: 12px;
    margin-left: 6px;
    /* backdrop-filter: invert(1); */
}
.bookmark {
    display: -webkit-inline-flex;
}
.display {
    margin-left: 4px;
}

/* tag */
a.tag, a.filter{
    border:1px solid #ccc;
    padding:0px 6px;
    -moz-border-radius: 10px;
    border-radius: 10px;
}

.description {
    display: none;
}

`);

(function() {
    'use strict';

    function url_domain(data) {
        var a = document.createElement('a');
        a.href = data;
        return a.hostname;
    }

    function createElementFromHTML(htmlString) {
        var div = document.createElement('div');
        div.innerHTML = htmlString.trim();
        return div.firstChild;
    }

    function addLinkIcons(){
        var bookmarks = document.getElementsByClassName('bookmark_title');
        for (var i = 0; i < bookmarks.length; i++) {
            var domain = url_domain(bookmarks[i].href);
            // var domain_icon_url = `https://api.faviconkit.com/${domain}/16`;
            // var domain_icon_url = `https://www.google.com/s2/favicons?sz=64&domain_url=${domain}`;
            var domain_icon_url = `https://s2.googleusercontent.com/s2/favicons?sz=64&domain=${domain}`;
            // var domain_icon_url = `https://besticon-demo.herokuapp.com/icon?url=${domain}&size=80`;
            // var domain_icon_url = `https://f1.allesedv.com/${domain}`;
            console.log(domain_icon_url);
            var icon = createElementFromHTML(`<img class='url_icon' src=${domain_icon_url}>`)
            bookmarks[i].parentElement.parentElement.children[0].appendChild(icon);
        }
    }

    addLinkIcons();
})();