Skip to content

Instantly share code, notes, and snippets.

@Getaji
Last active March 28, 2021 11:19
Show Gist options
  • Save Getaji/f9f44b56e4b17192c96890f13bb3128e to your computer and use it in GitHub Desktop.
Save Getaji/f9f44b56e4b17192c96890f13bb3128e to your computer and use it in GitHub Desktop.
(() => {
if (globalThis.lastFloatedComment) lastFloatedComment.el.style.cssText = "";
const commentEls = document.getElementsByTagName(
"ytd-comment-thread-renderer"
);
const comments = [...commentEls].map((el, index) => {
const contentTextEl = el.querySelector("#content-text");
return {
author: el.querySelector("#author-text").innerText,
contentText: contentTextEl.innerText,
contentHTML: contentTextEl.innerHTML,
el,
index,
};
});
const targetProp = prompt(
"対象プロパティ(author, contentText, contentHTML)",
"contentText"
);
if (!targetProp) return;
const value = prompt("値", "セットリスト");
if (!value) return;
const matcherName = prompt("一致方式(in, eq, eqn, re)", "in");
const matcherMaker = {
in: (value) => (target) => target.includes(value),
eq: (value) => (target) => target === value,
eqn: (value) => {
const n = parseInt(value);
return (target) => target === n;
},
re: (value) => {
const re = new RegExp(value);
return (target) => re.test(target);
},
}[matcherName];
if (!matcherMaker) return;
const matcher = matcherMaker(value);
const comment = comments.find((comment) =>
matcher(comment[targetProp], value)
);
comment.el.style.cssText =
"position: fixed; top: 100px; right: 500px; width: 400px; height: 80vh; overflow-y: scroll; background-color: rgba(0, 0, 0, .3);";
globalThis.lastFloatedComment = comment;
})();
(()=>{globalThis.lastFloatedComment&&(lastFloatedComment.el.style.cssText="");const t=[...document.getElementsByTagName("ytd-comment-thread-renderer")].map((t,e)=>{const n=t.querySelector("#content-text");return{author:t.querySelector("#author-text").innerText,contentText:n.innerText,contentHTML:n.innerHTML,el:t,index:e}}),e=prompt("対象プロパティ(author, contentText, contentHTML)","contentText");if(!e)return;const n=prompt("値","セットリスト");if(!n)return;const o={in:t=>e=>e.includes(t),eq:t=>e=>e===t,eqn:t=>{const e=parseInt(t);return t=>t===e},re:t=>{const e=new RegExp(t);return t=>e.test(t)}}[prompt("一致方式(in, eq, eqn, re)","in")];if(!o)return;const r=o(n),s=t.find(t=>r(t[e],n));s.el.style.cssText="position: fixed; top: 100px; right: 500px; width: 400px; height: 80vh; overflow-y: scroll; background-color: rgba(0, 0, 0, .3);",globalThis.lastFloatedComment=s})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment