GitHub Toggle Issue Comments

A userscript that toggles issues/pull request comments & messages

当前为 2018-09-23 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name GitHub Toggle Issue Comments
  3. // @version 1.3.0
  4. // @description A userscript that toggles issues/pull request comments & messages
  5. // @license MIT
  6. // @author Rob Garrison
  7. // @namespace https://github.com/Mottie
  8. // @include https://github.com/*
  9. // @run-at document-idle
  10. // @grant GM_addStyle
  11. // @grant GM_getValue
  12. // @grant GM_setValue
  13. // @require https://greasyfork.org/scripts/28721-mutations/code/mutations.js?version=597950
  14. // @icon https://assets-cdn.github.com/pinned-octocat.svg
  15. // ==/UserScript==
  16. (() => {
  17. "use strict";
  18.  
  19. GM_addStyle(`
  20. .ghic-button { float:right; }
  21. .ghic-button .btn:hover div.select-menu-modal-holder { display:block; top:auto; bottom:25px; right:0; }
  22. .ghic-right { position:absolute; right:10px; top:9px; }
  23. .ghic-button .select-menu-header, .ghic-participants { cursor:default; display:block; }
  24. .ghic-participants { border-top:1px solid #484848; padding:15px; }
  25. .ghic-avatar { display:inline-block; float:left; margin: 0 2px 2px 0; cursor:pointer; position:relative; }
  26. .ghic-avatar:last-child { margin-bottom:5px; }
  27. .ghic-avatar.comments-hidden svg { display:block; position:absolute; top:-2px; left:-2px; z-index:1; }
  28. .ghic-avatar.comments-hidden img { opacity:0.5; }
  29. .ghic-button .dropdown-item { font-weight:normal; position:relative; }
  30. .ghic-button .dropdown-item span { font-weight:normal; opacity:.5; }
  31. .ghic-button .dropdown-item.ghic-has-content span { opacity:1; }
  32. .ghic-button .dropdown-item.ghic-checked span { font-weight:bold; }
  33. .ghic-button .dropdown-item.ghic-checked svg,
  34. .ghic-button .dropdown-item:not(.ghic-checked) .ghic-count { display:inline-block; }
  35. .ghic-button .ghic-count { margin-left:5px; }
  36. .ghic-button .select-menu-modal { margin:0; }
  37. .ghic-button .ghic-participants { margin-bottom:20px; }
  38. /* for testing: ".ghic-hidden { opacity: 0.3; } */
  39. .ghic-hidden, .ghic-hidden-participant, .ghic-avatar svg, .ghic-button .ghic-count,
  40. .ghic-hideReactions .comment-reactions,
  41. .select-menu-header.ghic-active + .select-menu-list .dropdown-item:not(.ghic-has-content) { display:none; }
  42. .ghic-menu-wrapper input[type=checkbox] { height:0; width:0; visibility:hidden; position:absolute; }
  43. .ghic-menu-wrapper .ghic-toggle { cursor:pointer; text-indent:-9999px; width:20px; height:10px;
  44. background:grey; display:block; border-radius:10px; position:relative; }
  45. .ghic-menu-wrapper .ghic-toggle:after { content:''; position:absolute; top:0; left:1px; width:9px;
  46. height:9px; background:#fff; border-radius:9px; transition:.3s; }
  47. .ghic-menu-wrapper input:checked + .ghic-toggle { background:#070; }
  48. .ghic-menu-wrapper input:checked + .ghic-toggle:after { top:0; left:calc(100% - 1px);
  49. transform:translateX(-100%); }
  50. .ghic-menu-wrapper .ghic-toggle:active:after { width:13px; }
  51. `);
  52.  
  53. const regex = /(svg|path)/i,
  54. // ZenHub addon active (include ZenHub Enterprise)
  55. hasZenHub = $(".zhio, .zhe") ? true : false,
  56.  
  57. exceptions = [
  58. "ghsr-sort-block" // sort reactions block (github-sort-reactions.user.js)
  59. ],
  60.  
  61. settings = {
  62. // example: https://github.com/Mottie/Keyboard/issues/448
  63. title: {
  64. isHidden: false,
  65. name: "ghic-title",
  66. selector: ".discussion-item-renamed",
  67. label: "Title Changes"
  68. },
  69. labels: {
  70. isHidden: false,
  71. name: "ghic-labels",
  72. selector: ".discussion-item-labeled, .discussion-item-unlabeled",
  73. label: "Label Changes"
  74. },
  75. state: {
  76. isHidden: false,
  77. name: "ghic-state",
  78. selector: ".discussion-item-reopened, .discussion-item-closed",
  79. label: "State Changes (close/reopen)"
  80. },
  81.  
  82. // example: https://github.com/jquery/jquery/issues/2986
  83. milestone: {
  84. isHidden: false,
  85. name: "ghic-milestone",
  86. selector: ".discussion-item-milestoned",
  87. label: "Milestone Changes"
  88. },
  89. refs: {
  90. isHidden: false,
  91. name: "ghic-refs",
  92. selector: ".discussion-item",
  93. contains: ".discussion-item-ref-title",
  94. label: "References"
  95. },
  96. assigned: {
  97. isHidden: false,
  98. name: "ghic-assigned",
  99. selector: ".discussion-item-assigned",
  100. label: "Assignment Changes"
  101. },
  102.  
  103. // Pull Requests
  104. commits: {
  105. isHidden: false,
  106. name: "ghic-commits",
  107. selector: ".discussion-commits",
  108. label: "Commits"
  109. },
  110. reviews: {
  111. isHidden: false,
  112. name: "ghic-reviews",
  113. selector: ".discussion-item-review, .discussion-item-review_requested",
  114. label: "Reviews (All)"
  115. },
  116. outdated: {
  117. isHidden: false,
  118. name: "ghic-outdated",
  119. selector: ".discussion-item-review",
  120. contains: ".outdated-comment-label",
  121. label: "Reviews (Outdated)"
  122. },
  123. // example: https://github.com/jquery/jquery/pull/3014
  124. diffOld: {
  125. isHidden: false,
  126. name: "ghic-diffOld",
  127. selector: ".outdated-diff-comment-container",
  128. label: "Diff (outdated) Comments"
  129. },
  130. diffNew: {
  131. isHidden: false,
  132. name: "ghic-diffNew",
  133. selector: "[id^=diff-for-comment-]:not(.outdated-diff-comment-container)",
  134. label: "Diff (current) Comments"
  135. },
  136. // example: https://github.com/jquery/jquery/pull/2949
  137. merged: {
  138. isHidden: false,
  139. name: "ghic-merged",
  140. selector: ".discussion-item-merged",
  141. label: "Merged"
  142. },
  143. integrate: {
  144. isHidden: false,
  145. name: "ghic-integrate",
  146. selector: ".discussion-item-integrations-callout",
  147. label: "Integrations"
  148. },
  149.  
  150. // extras (special treatment - no selector)
  151. plus1: {
  152. isHidden: false,
  153. name: "ghic-plus1",
  154. label: "+1 Comments"
  155. },
  156. reactions: {
  157. isHidden: false,
  158. name: "ghic-reactions",
  159. label: "Reactions"
  160. },
  161. // page with lots of users to hide:
  162. // https://github.com/isaacs/github/issues/215
  163.  
  164. // ZenHub pipeline change
  165. pipeline: {
  166. isHidden: false,
  167. name: "ghic-pipeline",
  168. selector: ".discussion-item.zh-discussion-item",
  169. label: "ZenHub Pipeline Changes"
  170. }
  171. };
  172.  
  173. const iconHidden = `<svg class="octicon" xmlns="http://www.w3.org/2000/svg" width="30" height="30" viewBox="0 0 9 9"><path fill="#777" d="M7.07 4.5c0-.47-.12-.9-.35-1.3L3.2 6.7c.4.25.84.37 1.3.37.35 0 .68-.07 1-.2.32-.14.6-.32.82-.55.23-.23.4-.5.55-.82.13-.32.2-.65.2-1zM2.3 5.8l3.5-3.52c-.4-.23-.83-.35-1.3-.35-.35 0-.68.07-1 .2-.3.14-.6.32-.82.55-.23.23-.4.5-.55.82-.13.32-.2.65-.2 1 0 .47.12.9.36 1.3zm6.06-1.3c0 .7-.17 1.34-.52 1.94-.34.6-.8 1.05-1.4 1.4-.6.34-1.24.52-1.94.52s-1.34-.18-1.94-.52c-.6-.35-1.05-.8-1.4-1.4C.82 5.84.64 5.2.64 4.5s.18-1.35.52-1.94.8-1.06 1.4-1.4S3.8.64 4.5.64s1.35.17 1.94.52 1.06.8 1.4 1.4c.35.6.52 1.24.52 1.94z"/></svg>`,
  174. plus1Icon = `<img src="https://assets-cdn.github.com/images/icons/emoji/unicode/1f44d.png" class="emoji" title=":+1:" alt=":+1:" height="20" width="20" align="absmiddle">`;
  175.  
  176. function addMenu() {
  177. if ($("#discussion_bucket") && !$(".ghic-button")) {
  178. // update "isHidden" values
  179. getSettings();
  180. let name, hasContent, isHidden, isChecked,
  181. list = "",
  182. keys = Object.keys(settings),
  183. onlyActive = GM_getValue("onlyActive", false),
  184. header = $(".discussion-sidebar-item:last-child"),
  185. menu = document.createElement("div");
  186.  
  187. for (name of keys) {
  188. if (!(name === "pipeline" && !hasZenHub)) {
  189. // make plus1 and reactions list items always bright (has-content class)
  190. hasContent = name === "plus1" ? "ghic-has-content" : "";
  191. isHidden = settings[name].isHidden;
  192. isChecked = isHidden ? "" : "ghic-checked";
  193. // not using multi-line backticks because it adds lots of white-space to the label
  194. list += `<label class="dropdown-item ${hasContent} ${isChecked} ${settings[name].name}" data-ghic="${name}">
  195. <span>${settings[name].label} <span class="ghic-count"> </span></span>
  196. <span class="ghic-right">
  197. <input type="checkbox"${isHidden ? "" : " checked"}>
  198. <span class="ghic-toggle"></span>
  199. </span></label>`;
  200. }
  201. }
  202.  
  203. menu.className = "ghic-button";
  204. menu.innerHTML = `
  205. <span class="btn btn-sm" role="button" tabindex="0" aria-haspopup="true">
  206. <span class="tooltipped tooltipped-w" aria-label="Toggle issue comments">
  207. <svg class="octicon octicon-comment-discussion" height="16" width="16" role="img" viewBox="0 0 16 16">
  208. <path d="M15 2H6c-0.55 0-1 0.45-1 1v2H1c-0.55 0-1 0.45-1 1v6c0 0.55 0.45 1 1 1h1v3l3-3h4c0.55 0 1-0.45 1-1V10h1l3 3V10h1c0.55 0 1-0.45 1-1V3c0-0.55-0.45-1-1-1zM9 12H4.5l-1.5 1.5v-1.5H1V6h4v3c0 0.55 0.45 1 1 1h3v2z m6-3H13v1.5l-1.5-1.5H6V3h9v6z"></path>
  209. </svg>
  210. </span>
  211. <div class="select-menu-modal-holder ghic-menu-wrapper">
  212. <div class="select-menu-modal" aria-hidden="true">
  213. <div class="select-menu-header ${onlyActive ? "ghic-active" : ""}" tabindex="-1">
  214. <span class="select-menu-title">Toggle items</span>
  215. <label class="ghic-right tooltipped tooltipped-w" aria-label="Only show active items">
  216. <input id="ghic-only-active" type="checkbox" ${onlyActive ? "checked" : ""}>
  217. <span class="ghic-toggle"></span>
  218. </label>
  219. </div>
  220. <div class="select-menu-list ghic-menu" role="menu">
  221. ${list}
  222. <div class="ghic-participants"></div>
  223. </div>
  224. </div>
  225. </div>
  226. </span>
  227. `;
  228. if (hasZenHub) {
  229. header.insertBefore(menu, header.childNodes[0]);
  230. } else {
  231. header.appendChild(menu);
  232. }
  233. addAvatars();
  234. }
  235. update();
  236. }
  237.  
  238. function addAvatars() {
  239. let indx = 0,
  240.  
  241. str = "<p><strong>Hide Comments from</strong></p>",
  242. unique = [],
  243. // get all avatars
  244. avatars = $$(".timeline-comment-avatar img"),
  245. len = avatars.length - 1, // last avatar is the new comment with the current user
  246.  
  247. loop = (callback) => {
  248. let el, name,
  249. max = 0;
  250. while (max < 50 && indx < len) {
  251. if (indx >= len) {
  252. return callback();
  253. }
  254. el = avatars[indx];
  255. name = (el.getAttribute("alt") || "").replace("@", "");
  256. if (!unique.includes(name)) {
  257. str += `<span class="ghic-avatar tooltipped tooltipped-n" aria-label="${name}">
  258. ${iconHidden}
  259. <img class="ghic-avatar avatar" width="24" height="24" src="${el.src}"/>
  260. </span>`;
  261. unique[unique.length] = name;
  262. max++;
  263. }
  264. indx++;
  265. }
  266. if (indx < len) {
  267. setTimeout(() => {
  268. loop(callback);
  269. }, 200);
  270. } else {
  271. callback();
  272. }
  273. };
  274. loop(() => {
  275. $(".ghic-participants").innerHTML = str;
  276. });
  277. }
  278.  
  279. function getSettings() {
  280. let name,
  281. keys = Object.keys(settings);
  282. for (name of keys) {
  283. settings[name].isHidden = GM_getValue(settings[name].name, false);
  284. }
  285. }
  286.  
  287. function saveSettings() {
  288. let name,
  289. keys = Object.keys(settings);
  290. for (name of keys) {
  291. GM_setValue(settings[name].name, settings[name].isHidden);
  292. }
  293. }
  294.  
  295. function getInputValues() {
  296. let name, item,
  297. keys = Object.keys(settings),
  298. menu = $(".ghic-menu");
  299. for (name of keys) {
  300. if (!(name === "pipeline" && !hasZenHub)) {
  301. item = closest(".dropdown-item", $("." + settings[name].name, menu));
  302. if (item) {
  303. settings[name].isHidden = !$("input", item).checked;
  304. toggleClass(item, "ghic-checked", !settings[name].isHidden);
  305. }
  306. }
  307. }
  308. }
  309.  
  310. function hideStuff(name, init) {
  311. const obj = settings[name],
  312. isHidden = obj.isHidden;
  313. let count, results,
  314. item = $(".ghic-menu .dropdown-item." + obj.name);
  315. if (name === "plus1") {
  316. hidePlus1(init);
  317. } else if (item && name === "reactions") {
  318. toggleClass($("body"), "ghic-hideReactions", isHidden);
  319. toggleClass(item, "ghic-has-content", $$(".has-reactions").length - 1);
  320. // make first comment reactions visible
  321. item = $(".has-reactions", $(".timeline-comment-wrapper"));
  322. if (item) {
  323. item.style.display = "block";
  324. }
  325. } else if (item && obj.selector) {
  326. results = $$(obj.selector);
  327. if (obj.contains) {
  328. results = results.filter(el => {
  329. return !!$(obj.contains, el);
  330. });
  331. }
  332. toggleClass(item, "ghic-checked", !isHidden);
  333. if (isHidden) {
  334. count = addClass(results, "ghic-hidden");
  335. $(".ghic-count", item).textContent = count ? "(" + count + " hidden)" : " ";
  336. } else if (!init) {
  337. // no need to remove classes on initialization
  338. removeClass(results, "ghic-hidden");
  339. }
  340. toggleClass(item, "ghic-has-content", results.length);
  341. }
  342. }
  343.  
  344. function hidePlus1(init) {
  345. if (init && !settings.plus1.isHidden) {
  346. return;
  347. }
  348. let max,
  349. indx = 0,
  350. count = 0,
  351. total = 0,
  352. // keep a list of post authors to prevent duplicate +1 counts
  353. authors = [],
  354. // used https://github.com/isaacs/github/issues/215 for matches here...
  355. // matches "+1!!!!", "++1", "+!", "+99!!!", "-1", "+ 100", "thumbs up"; ":+1:^21425235"
  356. // ignoring -1's... add unicode for thumbs up; it gets replaced with an image in Windows
  357. regexPlus = /([?!*,.:^[\]()\'\"+-\d]|bump|thumbs|up|\ud83d\udc4d)/gi,
  358. // other comments to hide - they are still counted towards the +1 counter (for now?)
  359. // seen "^^^" to bump posts; "bump plleeaaassee"; "eta?"; "pretty please"
  360. // "need this"; "right now"; "still nothing?"; "super helpful"; "for gods sake"
  361. regexHide = new RegExp("(" + [
  362. "@\\w+",
  363. "\\b(it|is|a|so|the|and|no|on|oh|do|this|any|very|much|here|just|my)\\b",
  364. "pretty",
  365. "pl+e+a+s+e+",
  366. "y+e+s+",
  367. "eta",
  368. "fix",
  369. "right",
  370. "now",
  371. "hope(ful)?",
  372. "still",
  373. "wait(ed|ing)?",
  374. "nothing",
  375. "really",
  376. "add(ed|ing)?",
  377. "need(ed|ing)?",
  378. "updat(es|ed|ing)?",
  379. "back",
  380. "features?",
  381. "useful",
  382. "super",
  383. "helpful",
  384. "thanks",
  385. "for\\sgod'?s\\ssake",
  386. "c['emon]+" // c'mon, com'on, comeon
  387. ].join("|") + ")", "gi"),
  388. // image title ":{anything}:", etc.
  389. regexEmoji = /(:.*:)|[\u{1f300}-\u{1f64f}\u{1f680}-\u{1f6ff}\u{1f900}-\u{1f9ff}]/gu,
  390. regexWhitespace = /\s+/g,
  391.  
  392. comments = $$(".js-discussion .timeline-comment-wrapper")
  393. .filter(comment => {
  394. const classes = comment.className.split(" ");
  395. return !exceptions.some(ex => classes.includes(ex));
  396. }),
  397. len = comments.length,
  398.  
  399. loop = () => {
  400. let wrapper, el, tmp, txt, img, hasLink, dupe;
  401. max = 0;
  402. while (max < 20 && indx < len) {
  403. if (indx >= len) {
  404. return;
  405. }
  406. wrapper = comments[indx];
  407. // save author list to prevent repeat +1s
  408. el = $(".timeline-comment-header .author", wrapper);
  409. txt = (el ? el.textContent || "" : "").toLowerCase();
  410. dupe = true;
  411. if (txt && authors.indexOf(txt) < 0) {
  412. authors[authors.length] = txt;
  413. dupe = false;
  414. }
  415. el = $(".comment-body", wrapper);
  416. // ignore quoted messages, but get all fragments
  417. tmp = $$(".email-fragment", el);
  418. // some posts only contain a link to related issues; these should not be counted as a +1
  419. // see https://github.com/isaacs/github/issues/618#issuecomment-200869630
  420. hasLink = $$(tmp.length ? ".email-fragment .issue-link" : ".issue-link", el).length;
  421. if (tmp.length) {
  422. // ignore quoted messages
  423. txt = getAllText(tmp);
  424. } else {
  425. txt = (el ? el.textContent || "" : "").trim();
  426. }
  427. if (!txt) {
  428. img = $("img", el);
  429. if (img) {
  430. txt = img.getAttribute("title") || img.getAttribute("alt");
  431. }
  432. }
  433. // remove fluff
  434. txt = (txt || "")
  435. .replace(regexEmoji, "")
  436. .replace(regexHide, "")
  437. .replace(regexPlus, "")
  438. .replace(regexWhitespace, " ")
  439. .trim();
  440. if (txt === "" || (txt.length <= 4 && !hasLink)) {
  441. if (settings.plus1.isHidden) {
  442. wrapper.classList.add("ghic-hidden");
  443. total++;
  444. // one +1 per author
  445. if (!dupe) {
  446. count++;
  447. }
  448. } else if (!init) {
  449. wrapper.classList.remove("ghic-hidden");
  450. }
  451. max++;
  452. }
  453. indx++;
  454. }
  455. if (indx < len) {
  456. setTimeout(() => {
  457. window.requestAnimationFrame(loop);
  458. }, 200);
  459. } else {
  460. $(".ghic-menu .ghic-plus1 .ghic-count").textContent = total ? "(" + total + " hidden)" : " ";
  461. addCountToReaction(count);
  462. }
  463. };
  464. loop();
  465. }
  466.  
  467. function getAllText(el) {
  468. let txt = "",
  469. indx = el.length;
  470. // text order doesn't matter
  471. while (indx--) {
  472. txt += el[indx].textContent.trim();
  473. }
  474. return txt;
  475. }
  476.  
  477. function addCountToReaction(count) {
  478. if (!count) {
  479. count = ($(".ghic-menu .ghic-plus1 .ghic-count").textContent || "")
  480. .replace(/[()]/g, "")
  481. .trim();
  482. }
  483. let comment = $(".timeline-comment"),
  484. tmp = $(
  485. ".has-reactions button[value='+1 react'], .has-reactions button[value='+1 unreact']",
  486. comment
  487. ),
  488. el = $(".ghic-count", comment);
  489. if (el) {
  490. // the count may have been appended to the comment & now
  491. // there is a reaction, so remove any "ghic-count" elements
  492. el.parentNode.removeChild(el);
  493. }
  494. if (count) {
  495. if (tmp) {
  496. el = document.createElement("span");
  497. el.className = "ghic-count";
  498. el.textContent = count ? " + " + count + " (from hidden comments)" : "";
  499. tmp.appendChild(el);
  500. } else {
  501. el = document.createElement("p");
  502. el.className = "ghic-count";
  503. el.innerHTML = "<hr>" + plus1Icon + " " + count + " (from hidden comments)";
  504. $(".comment-body", comment).appendChild(el);
  505. }
  506. }
  507. }
  508.  
  509. function hideParticipant(el) {
  510. if (el) {
  511. el.classList.toggle("comments-hidden");
  512. let name = el.getAttribute("aria-label"),
  513. results = $$(
  514. ".timeline-comment-wrapper, .commit-comment, .discussion-item"
  515. ).filter(el => {
  516. const author = $(".js-discussion .author", el);
  517. return author ? name === author.textContent.trim() : false;
  518. });
  519. // use a different participant class name to hide timeline events
  520. // or unselecting all users will show everything
  521. if (el.classList.contains("comments-hidden")) {
  522. addClass(results, "ghic-hidden-participant");
  523. } else {
  524. removeClass(results, "ghic-hidden-participant");
  525. }
  526. results = [];
  527. }
  528. }
  529.  
  530. function update() {
  531. if ($("#discussion_bucket") && $(".ghic-button")) {
  532. let keys = Object.keys(settings),
  533. indx = keys.length;
  534. while (indx--) {
  535. // true flag for init - no need to remove classes
  536. hideStuff(keys[indx], true);
  537. }
  538. }
  539. }
  540.  
  541. function checkItem(event) {
  542. if (document.getElementById("discussion_bucket")) {
  543. let name,
  544. target = event.target,
  545. wrap = target && target.closest(".dropdown-item");
  546. if (target && wrap) {
  547. if (target.nodeName === "INPUT") {
  548. getInputValues();
  549. saveSettings();
  550. name = wrap.dataset.ghic;
  551. if (name) {
  552. hideStuff(name);
  553. }
  554. } else if (target.classList.contains("ghic-avatar")) {
  555. // make sure we're targeting the span wrapping the image
  556. hideParticipant(target.nodeName === "IMG" ? target.parentNode : target);
  557. } else if (regex.test(target.nodeName)) {
  558. // clicking on the SVG may target the svg or path inside
  559. hideParticipant(closest(".ghic-avatar", target));
  560. }
  561. } else if (target.id === "ghic-only-active") {
  562. closest(".select-menu-header", target).classList.toggle("ghic-active", target.checked);
  563. GM_setValue('onlyActive', target.checked);
  564. }
  565. // Make button show if it is active
  566. target = $(".ghic-button .btn");
  567. if (target) {
  568. const active = $$(".ghic-hidden, .ghic-hidden-participant").length > 0;
  569. target.classList.toggle("btn-outline", active);
  570. }
  571. }
  572. }
  573.  
  574. function $(selector, el) {
  575. return (el || document).querySelector(selector);
  576. }
  577.  
  578. function $$(selector, el) {
  579. return Array.from((el || document).querySelectorAll(selector));
  580. }
  581.  
  582. function closest(selector, el) {
  583. while (el && el.nodeType === 1) {
  584. if (el.matches(selector)) {
  585. return el;
  586. }
  587. el = el.parentNode;
  588. }
  589. return null;
  590. }
  591.  
  592. function addClass(els, name) {
  593. let indx,
  594. len = els.length;
  595. for (indx = 0; indx < len; indx++) {
  596. els[indx].classList.add(name);
  597. }
  598. return len;
  599. }
  600.  
  601. function removeClass(els, name) {
  602. let indx,
  603. len = els.length;
  604. for (indx = 0; indx < len; indx++) {
  605. els[indx].classList.remove(name);
  606. }
  607. }
  608.  
  609. function toggleClass(els, name, flag) {
  610. els = Array.isArray(els) ? els : [els];
  611. let el,
  612. indx = els.length;
  613. while (indx--) {
  614. el = els[indx];
  615. if (el) {
  616. if (typeof flag === "undefined") {
  617. flag = !el.classList.contains(name);
  618. }
  619. if (flag) {
  620. el.classList.add(name);
  621. } else {
  622. el.classList.remove(name);
  623. }
  624. }
  625. }
  626. }
  627.  
  628. function init() {
  629. getSettings();
  630. addMenu();
  631. $("body").addEventListener("click", checkItem);
  632. update();
  633. }
  634.  
  635. // update list when content changes
  636. document.addEventListener("ghmo:container", addMenu);
  637. document.addEventListener("ghmo:comments", update);
  638. init();
  639.  
  640. })();