Last active
March 11, 2016 16:53
-
-
Save Aquei/b8083013fcc9bfac7b9f to your computer and use it in GitHub Desktop.
Google Bookmarkのブックマークにfaviconをつけたり、新しいタブで開いたりする
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @description Google bookmarksのブックマークを新しいタブで開いたりfaviconを追加したりする | |
// @include https://www.google.co.jp/bookmarks/* | |
// @name Google Bookmark newtab | |
// @namespace https://gist.github.com/Aquei/b8083013fcc9bfac7b9f | |
// @version 1.0.1 | |
// ==/UserScript== | |
// @license Apache v2 License <http://www.apache.org/licenses/LICENSE-2.0> | |
'use strict'; | |
try{ | |
const bookmarks = document.querySelectorAll(`a[id^='bkmk_href_']`); | |
for(let bk of bookmarks){ | |
const ancUrl = new URL(bk.getAttribute("href")); | |
const bkUrl = new URL(ancUrl.searchParams.get("q")); | |
const host = bkUrl.host; | |
const endPoint = 'https://www.google.com/s2/favicons'; | |
//target="_blank" | |
bk.setAttribute("target", "_blank"); | |
//favicon | |
const favicon = document.createElement("img"); | |
favicon.setAttribute("style", "margin-right:5px;"); | |
const imgUrl = new URL(endPoint); | |
imgUrl.searchParams.append("domain", host); | |
//set | |
favicon.setAttribute("src", imgUrl.href); | |
bk.insertBefore(favicon, bk.firstChild); | |
} | |
}catch(e){ | |
//throw e; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment