Skip to content

Instantly share code, notes, and snippets.

@noromanba
Last active December 1, 2017 22:55
Show Gist options
  • Save noromanba/1862384 to your computer and use it in GitHub Desktop.
Save noromanba/1862384 to your computer and use it in GitHub Desktop.
Auto supplement Hatena::Star with AutoPatchWork / AutoPagerize for UserScript

*veedama* Hatena::Star AutoSupplement

Install

https://gist.github.com/noromanba/1862384/raw/veedama-hatenastar-autosupplement.user.js

About

Autopagerize / AutoPatchWork ❤ Hatena::Star

This is pager support script. When you use these pager on Hatena services, Hatena::Star vanished from inserted page. Fix it.

veedama-supplement-hatenastar

ATTENTION

This script is Experimental phase yet. At your own risks.

Known Problems

Doesn't work on Hatena Fotolife, some Hatelabo services

  • AutoPagerize_DOMNodeInserted and AutoPatchWork.DOMNodeInserted event is not fire.
  • Event is fired but not initialize Hatena::Star containers.

Not implements yet.

Closed Issue

Hatena Blog can use JavaScript. Therefore such collision to owner side pager support script often.

Native Ajax paging contents add @exclude section

These pages has implemented native auto paging and not fire "DOMNodeInserted" Event.

Support AutoPager Chrome("AutoPagerAfterInsert" Event)

AutoPager Chrome is no merit for Chromium. It's too slow. If you use this Extension, strongly recommends native AutoPager on Firefox. Because works well when auto paging with supplement stars.

Operating Environment

Browser UserScript Engine Pager
Google Chrome 17.0.963.56 m built-in Engine AutoPagerize 0.3.4 AutoPatchWork 1.9.5
Tampermonkey 2.4.2691
Firefox 10.0.2 Greasemonkey 0.9.17 AutoPagerize 0.9.5 AutoPagerize 0.0.63(GM)

Based On

This script patchwork these codes. Thanks for genius authors.

Author: hotchpotch aka secondlife

This Chrome Extension do the same thing. But malfunction on google search. Can not jump links when click search result. It's whiteout.

Extension source. It's works well when used as a UserScript. But duplicate paging-spacer on first paging position.

hatena-star-autopageload-duplicate-spacer

The script touch the core of HatenaStar.js.

This method is "How to produce like a 'GM unsafeWindow' on Chrome Extension content script context environment".

Author: os0x

This method is similar to the method of secondlife-san. "How to running Greasemonkey Scripts like a bookmarklet".

Author: nikolat aka Nikola

This method is a more safer than os0x-san and secondlife-san methods.

// ==UserScript==
// @name *veedama* Hatena::Star AutoSupplement
// @namespace https://www.hatena.ne.jp/noromanba/
// @description auto supplement Hatena Star with AutoPatchWork, AutoPagerize. AutoPager, Pagerization et al. for UserScript
// @include http://*
// @include https://*.hatena.tld/*
// @exclude http://serif.hatelabo.jp/*
// @exclude http://*.hatenablog.tld/*
// @exclude http://*.hatenadiary.tld/*
// @exclude http://*.hateblo.jp/*
// @version 2017.12.1.0
// @homepage https://gist.github.com/noromanba/1862384
// @downloadURL https://gist.github.com/noromanba/1862384/raw/veedama-hatenastar-autosupplement.user.js
// @updateURL https://gist.github.com/noromanba/1862384/raw/veedama-hatenastar-autosupplement.user.js
// @license MIT License https://nrm.mit-license.org/2012
// @author noromanba https://noromanba.github.com
// @icon https://upload.wikimedia.org/wikipedia/commons/3/3f/Koch_snowflake_%28RGB-CMY%29.jpg
// ==/UserScript==
// Icon (Public Domain by Solkoll)
// https://commons.wikimedia.org/wiki/File%3AKoch_snowflake_%28RGB-CMY%29.jpg
// Devel
// https://gist.github.com/1862384
(() => {
'use strict';
// c.f.
// https://github.com/hotchpotch/hatena-star-autopageload-googlechrome/blob/master/src/HatenaStarLoad.js
const supplyStar = () => {
const Hatena = window.Hatena;
if (!Hatena || !Hatena.Star) return;
// XXX duplication and high cpu/time usage on many stars page e.g.
// http://ptech.g.hatena.ne.jp/noromanba/archive
const loadContainer = (node) => {
if (Hatena.Star.EntryLoader && Hatena.Star.EntryLoader.loadNewEntries) {
Hatena.Star.EntryLoader.loadNewEntries(node);
}
};
// TODO debouncing function calls or replace to MutationObserber
//*/
[
'AutoPatchWork.DOMNodeInserted',
'AutoPagerize_DOMNodeInserted',
'AutoPagerAfterInsert',
'Pagerization.DOMNodeInserted',
].forEach(paging => {
document.body.addEventListener(paging, evt => {
loadContainer(evt.target);
});
});
/*/
// XXX once per auto-pagenation
new MutationObserver(records => {
records.forEach(record => {
loadContainer(record.target);
});
}).observe(document.body, { childList: true, subtree: true });
//*/
};
// c.f.
// http://subtech.g.hatena.ne.jp/secondlife/20091228/1262001989
// https://gist.github.com/nikolat/761858
// https://blog.mono0x.net/blog/2014/07/13/greasemonkey-2-dot-0/
const injectContentContext = (() => {
const wall = document.head || document.body || document.documentElement;
const container = wall.appendChild(Object.assign(document.createElement('script'), {
charset: 'utf-8',
}));
return (funcOrString) => {
container.appendChild(document.createTextNode('(' + funcOrString.toString() + ')();\n'));
};
})();
injectContentContext(supplyStar);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment