/*
* @title Hatena::Haiku::Filter
* @description はてなハイクのタイムラインを自分の投稿だけにする(Proxy を使ってみたかっただけ
* @include http://h.hatena.ne.jp/*
* @license MIT License
* @javascript_url
*/
(() => {
const d_ = document;
/* make height 0 of .blank-entry */
d_.head.appendChild(Object.assign(d_.createElement("style"), {
innerHTML: `
div.stream div.entries div.entry.tl-entry.blank-entry {
padding: 0;
border-bottom: none;
}
`,
}));
const def = {
user: Hatena.Visitor.name,
};
function is_match(entry) {
return [
entry => {
let e = entry.querySelector(".info > .username > a");
return e.title == `id:${def.user}`;
},
].find(f => ! f.call(null, entry)) == null;
}
TL.Entry = new Proxy(TL.Entry, {
construct: (target, args) => {
let obj = new target(...args);
if (! is_match(obj.element)) {
obj.element.innerHTML = "";
obj.element.classList.add("blank-entry");
obj.eid = -1;
}
return obj;
},
});
function auto_pagerize() {
let pager = d_.querySelector("div.pager a.pager-older");
const y1 = pager.getBoundingClientRect().top;
const y2 = window.innerHeight;
if (y1 < y2) {
pager.click();
}
}
TL.View.prototype.stopNextIndicator = new Proxy(TL.View.prototype.stopNextIndicator, {
apply: (target, thisArg, args) => {
auto_pagerize();
return target.apply(thisArg, args);
},
});
d_.querySelectorAll(".tl-entry-list > .tl-entry").forEach(entry => {
if (! is_match(entry)) {
entry.style.display = "none";
}
});
auto_pagerize();
})();