勝手にスター (窓が出る)

    @@ -1,33 +1,61 @@ /* - * @title 勝手にスター - * @description 勝手に はてなスターを置きます + * @title 勝手にスター (窓が出る) + * @description 勝手にはてなスターを置くウィンドウを出します。 * @include http://* * @include https://* + * @exclude http://s.hatena.ne.jp/* + * @exclude http://b.hatena.ne.jp/* * @license MIT License * @javascript_url */ -// inspired by http://let.hatelabo.jp/noromanba/let/gYC-xcvQ3PTQew + (() => { - const d_ = document - if (! d_.querySelector('script[src*="s.hatena.ne.jp/js/HatenaStar.js"]')) { - d_.head.appendChild(Object.assign(d_.createElement("script"), { - type: "text/javascript", - src: "//s.hatena.ne.jp/js/HatenaStar.js", - onload: function() { - let e = d_.querySelector("h1,h2,h3,h4,h5,h6") - Hatena.Star.SiteConfig = { - entryNodes: {} - } - Hatena.Star.SiteConfig.entryNodes[ e.tagName ] = { - uri: "document.location", - title: "document.title", - container: "parent", - } - new Hatena.Star.EntryLoader(); - }, - })) - } else { - console.log("already Hatena.Star exists !") - } -})() + const freestar = () => { + + const conf = Object.assign({}, Hatena.Star.SiteConfig); + Hatena.Star.SiteConfig = { entryNodes: { + 'div.hatenalet-free-star': { + uri: 'a', + title: 'document.title', + container: 'parent' + } + } }; + + // http://let.hatelabo.jp/noromanba/let/gYC-yczpqbSRXw + // https://ptech.g.hatena.ne.jp/noromanba/20120330/1333139149 + new (new Ten.Class({ + base: [Ten.SubWindow], + initialize: function() { + var self = this.constructor.SUPER.call(this); + self.container.appendChild(Ten.Element( + 'a', { href: canonical(), style: { textDecoration: 'none' } }, '?' + )); + self.container.className = 'hatenalet-free-star'; + self.show({ x: window.pageXOffset + 1, y: window.pageYOffset + 1 }); + return self; + }, + style: { + textAlign: 'left', + width: 'auto', + height: 'auto' + } + },{}))(); + + new Hatena.Star.EntryLoader(); + Hatena.Star.SiteConfig = conf; + + }; + + // https://gist.github.com/noromanba/d730ccf3ae5e6916cd60 + const canonical = () => ((document.querySelector('head meta[property="og:url"][content]') || {}).content || + (document.querySelector('head link[rel="canonical"][href]') || {}).href || + location.href); + + if (window.Hatena && Hatena.Star) freestar(); + else (document.head || document.body).appendChild(Object.assign(document.createElement('script'), { + type: 'text/javascript', + src: '//s.hatena.ne.jp/js/HatenaStar.js' + })).addEventListener('load', freestar, false); + +})();
  • /*
     * @title 勝手にスター (窓が出る)
     * @description 勝手にはてなスターを置くウィンドウを出します。
     * @include http://*
     * @include https://*
     * @exclude http://s.hatena.ne.jp/*
     * @exclude http://b.hatena.ne.jp/*
     * @license MIT License
     * @javascript_url
     */
    
    (() => {
    
    	const freestar = () => {
    
    		const conf = Object.assign({}, Hatena.Star.SiteConfig);
    		Hatena.Star.SiteConfig = { entryNodes: {
    			'div.hatenalet-free-star': {
    				uri: 'a',
    				title: 'document.title',
    				container: 'parent'
    			}
    		} };
    
    		// http://let.hatelabo.jp/noromanba/let/gYC-yczpqbSRXw
    		// https://ptech.g.hatena.ne.jp/noromanba/20120330/1333139149
    		new (new Ten.Class({
    			base: [Ten.SubWindow],
    			initialize: function() {
    				var self = this.constructor.SUPER.call(this);
    				self.container.appendChild(Ten.Element(
    				 'a', { href: canonical(), style: { textDecoration: 'none' } }, '?'
    				));
    				self.container.className = 'hatenalet-free-star';
    				self.show({ x: window.pageXOffset + 1, y: window.pageYOffset + 1 });
    				return self;
    			},
    			style: {
    			 textAlign: 'left',
    			 width: 'auto',
    			 height: 'auto'
    			}
    		},{}))();
    
    		new Hatena.Star.EntryLoader();
    		Hatena.Star.SiteConfig = conf;
    
    	};
    
    	// https://gist.github.com/noromanba/d730ccf3ae5e6916cd60
    	const canonical = () => ((document.querySelector('head meta[property="og:url"][content]') || {}).content ||
    	 (document.querySelector('head link[rel="canonical"][href]') || {}).href ||
    	 location.href);
    
    	if (window.Hatena && Hatena.Star) freestar();
    	 else (document.head || document.body).appendChild(Object.assign(document.createElement('script'), {
    		type: 'text/javascript',
    		src: '//s.hatena.ne.jp/js/HatenaStar.js'
    	 })).addEventListener('load', freestar, false);
    
    })();
    
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。

History

  1. 2017/02/21 21:40:06 - 2017-02-21
  2. 2017/02/21 12:09:27 - 2017-02-21
  3. 2017/02/21 00:23:14 - 2017-02-21
  4. 2017/02/21 00:23:06 - 2017-02-21