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

  • /*
     * @title 勝手にスター (窓が出る)
     * @description 勝手にはてなスターを置くウィンドウを出します。
     * @include http://*
     * @include https://*
     * @license MIT License
     * @javascript_url
     */
    
    (() => {
    
    	const freestar = () => {
    
    		const pos = { x: window.pageXOffset + 1, y: window.pageYOffset + 1 };
    
    		if (Hatena.Star.FreeStarWin) return(Hatena.Star.FreeStarWin.show(pos));
    
    		const c = Hatena.Star.EntryLoader;
    		let conf = { entryNodes: {
    			'div.hatenalet-free-star': {
    				uri: 'a',
    				title: 'document.title',
    				container: 'parent'
    			}
    		} };
    		let header = ['div', 'hatenalet-free-star'];
    		[Hatena.Star.SiteConfig, conf] = [conf, Hatena.Star.SiteConfig];
    		if (c.headerTagAndClassName) [c.headerTagAndClassName, header] = [header, c.headerTagAndClassName];
    
    		// http://let.hatelabo.jp/noromanba/let/gYC-yczpqbSRXw
    		// https://ptech.g.hatena.ne.jp/noromanba/20120330/1333139149
    		Hatena.Star.FreeStarWin = 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' } }, document.title
    				));
    				self.container.className = 'hatenalet-free-star';
    				self.show(pos);
    				return self;
    			},
    			style: {
    			 textAlign: 'left'
    			},
    			containerStyle: {
    			 margin: '32px 0 0 0',
    			 padding: '0.5em',
    			 fontSize: '80%'
    			},
    			closeButton: '//s.hatena.ne.jp/images/close.gif'
    		},{}))();
    
    		if (Hatena.Bookmark && Hatena.Bookmark.Star)
    		 Hatena.Bookmark.Star.loadStarPartially(1, 'div.hatenalet-free-star');
    		 else new c();
    
    		[Hatena.Star.SiteConfig, conf] = [conf, Hatena.Star.SiteConfig];
    		if (c.headerTagAndClassName) [c.headerTagAndClassName, header] = [header, c.headerTagAndClassName];
    
    	};
    
    	// 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 && Hatena.Star.EntryLoader) 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);
    
    })();
    
    /*
    s.hatena.ne.jp でも出るようになったけど場所によっては (/userID/stars とか) 奈落に呑まれて消せなくなるから
    その時は star.delete.json とかを自力で呼んで消すしかない
    (☆データ自体は存在してる、けど entries.json で返してもらえない)
    */
  • 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