Skip to content

Instantly share code, notes, and snippets.

@Aquei
Last active March 11, 2016 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Aquei/b8083013fcc9bfac7b9f to your computer and use it in GitHub Desktop.
Save Aquei/b8083013fcc9bfac7b9f to your computer and use it in GitHub Desktop.
Google Bookmarkのブックマークにfaviconをつけたり、新しいタブで開いたりする
// ==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