B站用户屏蔽

隐藏不感兴趣的内容,支持用户、首页频道推广和广告。

  1. // ==UserScript==
  2. // @name B站用户屏蔽
  3. // @namespace https://github.com/NateScarlet/Scripts/tree/master/user-script
  4. // @description 隐藏不感兴趣的内容,支持用户、首页频道推广和广告。
  5. // @grant GM.getValue
  6. // @grant GM.setValue
  7. // @grant GM.deleteValue
  8. // @include https://search.bilibili.com/*
  9. // @include https://space.bilibili.com/*
  10. // @include https://www.bilibili.com/*
  11. // @include https://live.bilibili.com/*
  12. // @run-at document-start
  13. // @version 2024.12.09+107e7a46
  14. // ==/UserScript==
  15.  
  16. "use strict";
  17. (() => {
  18. var __defProp = Object.defineProperty;
  19. var __defProps = Object.defineProperties;
  20. var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
  21. var __getOwnPropSymbols = Object.getOwnPropertySymbols;
  22. var __hasOwnProp = Object.prototype.hasOwnProperty;
  23. var __propIsEnum = Object.prototype.propertyIsEnumerable;
  24. var __pow = Math.pow;
  25. var __defNormalProp = (obj, key2, value) => key2 in obj ? __defProp(obj, key2, { enumerable: true, configurable: true, writable: true, value }) : obj[key2] = value;
  26. var __spreadValues = (a, b) => {
  27. for (var prop in b || (b = {}))
  28. if (__hasOwnProp.call(b, prop))
  29. __defNormalProp(a, prop, b[prop]);
  30. if (__getOwnPropSymbols)
  31. for (var prop of __getOwnPropSymbols(b)) {
  32. if (__propIsEnum.call(b, prop))
  33. __defNormalProp(a, prop, b[prop]);
  34. }
  35. return a;
  36. };
  37. var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
  38. var __publicField = (obj, key2, value) => {
  39. __defNormalProp(obj, typeof key2 !== "symbol" ? key2 + "" : key2, value);
  40. return value;
  41. };
  42. var __async = (__this, __arguments, generator) => {
  43. return new Promise((resolve, reject) => {
  44. var fulfilled = (value) => {
  45. try {
  46. step(generator.next(value));
  47. } catch (e) {
  48. reject(e);
  49. }
  50. };
  51. var rejected = (value) => {
  52. try {
  53. step(generator.throw(value));
  54. } catch (e) {
  55. reject(e);
  56. }
  57. };
  58. var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
  59. step((generator = generator.apply(__this, __arguments)).next());
  60. });
  61. };
  62.  
  63. // src/utils/onDocumentReadyOnce.ts
  64. function onDocumentReadyOnce(cb) {
  65. if (document.readyState == "complete") {
  66. cb();
  67. } else {
  68. window.addEventListener("load", cb, { once: true });
  69. }
  70. }
  71.  
  72. // src/utils/Polling.ts
  73. var Polling = class {
  74. constructor({
  75. update,
  76. scheduleNext = requestAnimationFrame
  77. }) {
  78. __publicField(this, "update");
  79. __publicField(this, "scheduleNext");
  80. __publicField(this, "didRequestedStop", false);
  81. __publicField(this, "workerCount", 0);
  82. __publicField(this, "start", () => {
  83. this.didRequestedStop = false;
  84. if (this.isRunning) {
  85. return;
  86. }
  87. this.run();
  88. });
  89. __publicField(this, "stop", () => {
  90. this.didRequestedStop = true;
  91. });
  92. __publicField(this, "dispose", () => {
  93. this.stop();
  94. });
  95. this.update = update;
  96. this.scheduleNext = scheduleNext;
  97. this.start();
  98. }
  99. run() {
  100. return __async(this, null, function* () {
  101. this.workerCount += 1;
  102. try {
  103. while (!this.didRequestedStop) {
  104. yield this.update();
  105. yield new Promise((resolve) => {
  106. this.scheduleNext(resolve);
  107. });
  108. }
  109. } finally {
  110. this.workerCount -= 1;
  111. }
  112. });
  113. }
  114. get isRunning() {
  115. return this.workerCount > 0;
  116. }
  117. };
  118.  
  119. // src/utils/Disposal.ts
  120. var Disposal = class {
  121. constructor() {
  122. __publicField(this, "filo", []);
  123. __publicField(this, "push", (d2) => {
  124. this.filo.push(d2);
  125. });
  126. __publicField(this, "dispose", () => {
  127. while (this.filo.length > 0) {
  128. const next = this.filo.pop();
  129. if (next) {
  130. next.dispose();
  131. }
  132. }
  133. });
  134. }
  135. };
  136.  
  137. // src/utils/waitUntil.ts
  138. function waitUntil(_0) {
  139. return __async(this, arguments, function* ({
  140. ready,
  141. timeoutMs = 6e4,
  142. debounceMs = 500,
  143. onTimeout = () => {
  144. throw new Error("wait timeout");
  145. },
  146. scheduleNext = (next) => setTimeout(next, 100)
  147. }) {
  148. const startAt = performance.now();
  149. let readyAt = 0;
  150. do {
  151. if (yield ready()) {
  152. if (!readyAt) {
  153. readyAt = performance.now();
  154. }
  155. } else {
  156. readyAt = 0;
  157. }
  158. yield new Promise((resolve) => {
  159. scheduleNext(resolve);
  160. });
  161. if (performance.now() - startAt > timeoutMs) {
  162. return onTimeout();
  163. }
  164. } while (readyAt === 0 || performance.now() - readyAt <= debounceMs);
  165. });
  166. }
  167.  
  168. // src/utils/obtainHTMLElementByID.ts
  169. function obtainHTMLElementByID({
  170. tag: tag2,
  171. id,
  172. onDidCreate
  173. }) {
  174. const match = document.getElementById(id);
  175. if (match) {
  176. return match;
  177. }
  178. const el = document.createElement(tag2);
  179. el.id = id;
  180. onDidCreate == null ? void 0 : onDidCreate(el);
  181. return el;
  182. }
  183.  
  184. // src/utils/randomUUID.ts
  185. function fallback() {
  186. const ts = typeof performance !== "undefined" && performance.now ? performance.now() : Date.now();
  187. return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
  188. const r = (ts + Math.random()) * 16 % 16 | 0;
  189. const v = c === "x" ? r : r & 3 | 8;
  190. return v.toString(16);
  191. });
  192. }
  193. function randomUUID() {
  194. if (window.isSecureContext && typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
  195. return crypto.randomUUID();
  196. }
  197. return fallback();
  198. }
  199.  
  200. // node_modules/.pnpm/@mdi+js@7.2.96/node_modules/@mdi/js/mdi.js
  201. var mdiAccountCancelOutline = "M10 4A4 4 0 0 0 6 8A4 4 0 0 0 10 12A4 4 0 0 0 14 8A4 4 0 0 0 10 4M10 6A2 2 0 0 1 12 8A2 2 0 0 1 10 10A2 2 0 0 1 8 8A2 2 0 0 1 10 6M10 13C7.33 13 2 14.33 2 17V20H11.5A6.5 6.5 0 0 1 11.03 18.1H3.9V17C3.9 16.36 7.03 14.9 10 14.9C10.5 14.9 11 14.95 11.5 15.03A6.5 6.5 0 0 1 12.55 13.29C11.61 13.1 10.71 13 10 13M17.5 13C15 13 13 15 13 17.5C13 20 15 22 17.5 22C20 22 22 20 22 17.5C22 15 20 13 17.5 13M17.5 14.5C19.16 14.5 20.5 15.84 20.5 17.5C20.5 18.06 20.35 18.58 20.08 19L16 14.92C16.42 14.65 16.94 14.5 17.5 14.5M14.92 16L19 20.08C18.58 20.35 18.06 20.5 17.5 20.5C15.84 20.5 14.5 19.16 14.5 17.5C14.5 16.94 14.65 16.42 14.92 16Z";
  202. var mdiAccountCheckOutline = "M21.1,12.5L22.5,13.91L15.97,20.5L12.5,17L13.9,15.59L15.97,17.67L21.1,12.5M11,4A4,4 0 0,1 15,8A4,4 0 0,1 11,12A4,4 0 0,1 7,8A4,4 0 0,1 11,4M11,6A2,2 0 0,0 9,8A2,2 0 0,0 11,10A2,2 0 0,0 13,8A2,2 0 0,0 11,6M11,13C11.68,13 12.5,13.09 13.41,13.26L11.74,14.93L11,14.9C8.03,14.9 4.9,16.36 4.9,17V18.1H11.1L13,20H3V17C3,14.34 8.33,13 11,13Z";
  203. var mdiCancel = "M12 2C17.5 2 22 6.5 22 12S17.5 22 12 22 2 17.5 2 12 6.5 2 12 2M12 4C10.1 4 8.4 4.6 7.1 5.7L18.3 16.9C19.3 15.5 20 13.8 20 12C20 7.6 16.4 4 12 4M16.9 18.3L5.7 7.1C4.6 8.4 4 10.1 4 12C4 16.4 7.6 20 12 20C13.9 20 15.6 19.4 16.9 18.3Z";
  204. var mdiCheck = "M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z";
  205. var mdiCheckCircleOutline = "M12 2C6.5 2 2 6.5 2 12S6.5 22 12 22 22 17.5 22 12 17.5 2 12 2M12 20C7.59 20 4 16.41 4 12S7.59 4 12 4 20 7.59 20 12 16.41 20 12 20M16.59 7.58L10 14.17L7.41 11.59L6 13L10 17L18 9L16.59 7.58Z";
  206. var mdiClose = "M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z";
  207. var mdiEyeOff = "M11.83,9L15,12.16C15,12.11 15,12.05 15,12A3,3 0 0,0 12,9C11.94,9 11.89,9 11.83,9M7.53,9.8L9.08,11.35C9.03,11.56 9,11.77 9,12A3,3 0 0,0 12,15C12.22,15 12.44,14.97 12.65,14.92L14.2,16.47C13.53,16.8 12.79,17 12,17A5,5 0 0,1 7,12C7,11.21 7.2,10.47 7.53,9.8M2,4.27L4.28,6.55L4.73,7C3.08,8.3 1.78,10 1,12C2.73,16.39 7,19.5 12,19.5C13.55,19.5 15.03,19.2 16.38,18.66L16.81,19.08L19.73,22L21,20.73L3.27,3M12,7A5,5 0 0,1 17,12C17,12.64 16.87,13.26 16.64,13.82L19.57,16.75C21.07,15.5 22.27,13.86 23,12C21.27,7.61 17,4.5 12,4.5C10.6,4.5 9.26,4.75 8,5.2L10.17,7.35C10.74,7.13 11.35,7 12,7Z";
  208. var mdiEyeOffOutline = "M2,5.27L3.28,4L20,20.72L18.73,22L15.65,18.92C14.5,19.3 13.28,19.5 12,19.5C7,19.5 2.73,16.39 1,12C1.69,10.24 2.79,8.69 4.19,7.46L2,5.27M12,9A3,3 0 0,1 15,12C15,12.35 14.94,12.69 14.83,13L11,9.17C11.31,9.06 11.65,9 12,9M12,4.5C17,4.5 21.27,7.61 23,12C22.18,14.08 20.79,15.88 19,17.19L17.58,15.76C18.94,14.82 20.06,13.54 20.82,12C19.17,8.64 15.76,6.5 12,6.5C10.91,6.5 9.84,6.68 8.84,7L7.3,5.47C8.74,4.85 10.33,4.5 12,4.5M3.18,12C4.83,15.36 8.24,17.5 12,17.5C12.69,17.5 13.37,17.43 14,17.29L11.72,15C10.29,14.85 9.15,13.71 9,12.28L5.6,8.87C4.61,9.72 3.78,10.78 3.18,12Z";
  209. var mdiOpenInNew = "M14,3V5H17.59L7.76,14.83L9.17,16.24L19,6.41V10H21V3M19,19H5V5H12V3H5C3.89,3 3,3.9 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V12H19V19Z";
  210.  
  211. // node_modules/.pnpm/lit-html@2.7.3/node_modules/lit-html/development/lit-html.js
  212. var _a;
  213. var _b;
  214. var _c;
  215. var _d;
  216. var DEV_MODE = false;
  217. var ENABLE_EXTRA_SECURITY_HOOKS = true;
  218. var ENABLE_SHADYDOM_NOPATCH = true;
  219. var NODE_MODE = false;
  220. var global2 = NODE_MODE ? globalThis : window;
  221. var debugLogEvent = DEV_MODE ? (event) => {
  222. const shouldEmit = global2.emitLitDebugLogEvents;
  223. if (!shouldEmit) {
  224. return;
  225. }
  226. global2.dispatchEvent(new CustomEvent("lit-debug", {
  227. detail: event
  228. }));
  229. } : void 0;
  230. var debugLogRenderId = 0;
  231. var issueWarning;
  232. if (DEV_MODE) {
  233. (_a = global2.litIssuedWarnings) !== null && _a !== void 0 ? _a : global2.litIssuedWarnings = /* @__PURE__ */ new Set();
  234. issueWarning = (code, warning) => {
  235. warning += code ? ` See https://lit.dev/msg/${code} for more information.` : "";
  236. if (!global2.litIssuedWarnings.has(warning)) {
  237. console.warn(warning);
  238. global2.litIssuedWarnings.add(warning);
  239. }
  240. };
  241. issueWarning("dev-mode", `Lit is in dev mode. Not recommended for production!`);
  242. }
  243. var wrap = ENABLE_SHADYDOM_NOPATCH && ((_b = global2.ShadyDOM) === null || _b === void 0 ? void 0 : _b.inUse) && ((_c = global2.ShadyDOM) === null || _c === void 0 ? void 0 : _c.noPatch) === true ? global2.ShadyDOM.wrap : (node) => node;
  244. var trustedTypes = global2.trustedTypes;
  245. var policy = trustedTypes ? trustedTypes.createPolicy("lit-html", {
  246. createHTML: (s) => s
  247. }) : void 0;
  248. var identityFunction = (value) => value;
  249. var noopSanitizer = (_node, _name, _type) => identityFunction;
  250. var setSanitizer = (newSanitizer) => {
  251. if (!ENABLE_EXTRA_SECURITY_HOOKS) {
  252. return;
  253. }
  254. if (sanitizerFactoryInternal !== noopSanitizer) {
  255. throw new Error(`Attempted to overwrite existing lit-html security policy. setSanitizeDOMValueFactory should be called at most once.`);
  256. }
  257. sanitizerFactoryInternal = newSanitizer;
  258. };
  259. var _testOnlyClearSanitizerFactoryDoNotCallOrElse = () => {
  260. sanitizerFactoryInternal = noopSanitizer;
  261. };
  262. var createSanitizer = (node, name, type) => {
  263. return sanitizerFactoryInternal(node, name, type);
  264. };
  265. var boundAttributeSuffix = "$lit$";
  266. var marker = `lit$${String(Math.random()).slice(9)}$`;
  267. var markerMatch = "?" + marker;
  268. var nodeMarker = `<${markerMatch}>`;
  269. var d = NODE_MODE && global2.document === void 0 ? {
  270. createTreeWalker() {
  271. return {};
  272. }
  273. } : document;
  274. var createMarker = () => d.createComment("");
  275. var isPrimitive = (value) => value === null || typeof value != "object" && typeof value != "function";
  276. var isArray = Array.isArray;
  277. var isIterable = (value) => isArray(value) || // eslint-disable-next-line @typescript-eslint/no-explicit-any
  278. typeof (value === null || value === void 0 ? void 0 : value[Symbol.iterator]) === "function";
  279. var SPACE_CHAR = `[
  280. \f\r]`;
  281. var ATTR_VALUE_CHAR = `[^
  282. \f\r"'\`<>=]`;
  283. var NAME_CHAR = `[^\\s"'>=/]`;
  284. var textEndRegex = /<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g;
  285. var COMMENT_START = 1;
  286. var TAG_NAME = 2;
  287. var DYNAMIC_TAG_NAME = 3;
  288. var commentEndRegex = /-->/g;
  289. var comment2EndRegex = />/g;
  290. var tagEndRegex = new RegExp(`>|${SPACE_CHAR}(?:(${NAME_CHAR}+)(${SPACE_CHAR}*=${SPACE_CHAR}*(?:${ATTR_VALUE_CHAR}|("|')|))|$)`, "g");
  291. var ENTIRE_MATCH = 0;
  292. var ATTRIBUTE_NAME = 1;
  293. var SPACES_AND_EQUALS = 2;
  294. var QUOTE_CHAR = 3;
  295. var singleQuoteAttrEndRegex = /'/g;
  296. var doubleQuoteAttrEndRegex = /"/g;
  297. var rawTextElement = /^(?:script|style|textarea|title)$/i;
  298. var HTML_RESULT = 1;
  299. var SVG_RESULT = 2;
  300. var ATTRIBUTE_PART = 1;
  301. var CHILD_PART = 2;
  302. var PROPERTY_PART = 3;
  303. var BOOLEAN_ATTRIBUTE_PART = 4;
  304. var EVENT_PART = 5;
  305. var ELEMENT_PART = 6;
  306. var COMMENT_PART = 7;
  307. var tag = (type) => (strings, ...values) => {
  308. if (DEV_MODE && strings.some((s) => s === void 0)) {
  309. console.warn("Some template strings are undefined.\nThis is probably caused by illegal octal escape sequences.");
  310. }
  311. return {
  312. // This property needs to remain unminified.
  313. ["_$litType$"]: type,
  314. strings,
  315. values
  316. };
  317. };
  318. var html = tag(HTML_RESULT);
  319. var svg = tag(SVG_RESULT);
  320. var noChange = Symbol.for("lit-noChange");
  321. var nothing = Symbol.for("lit-nothing");
  322. var templateCache = /* @__PURE__ */ new WeakMap();
  323. var walker = d.createTreeWalker(d, 129, null, false);
  324. var sanitizerFactoryInternal = noopSanitizer;
  325. var getTemplateHtml = (strings, type) => {
  326. const l = strings.length - 1;
  327. const attrNames = [];
  328. let html2 = type === SVG_RESULT ? "<svg>" : "";
  329. let rawTextEndRegex;
  330. let regex = textEndRegex;
  331. for (let i = 0; i < l; i++) {
  332. const s = strings[i];
  333. let attrNameEndIndex = -1;
  334. let attrName;
  335. let lastIndex = 0;
  336. let match;
  337. while (lastIndex < s.length) {
  338. regex.lastIndex = lastIndex;
  339. match = regex.exec(s);
  340. if (match === null) {
  341. break;
  342. }
  343. lastIndex = regex.lastIndex;
  344. if (regex === textEndRegex) {
  345. if (match[COMMENT_START] === "!--") {
  346. regex = commentEndRegex;
  347. } else if (match[COMMENT_START] !== void 0) {
  348. regex = comment2EndRegex;
  349. } else if (match[TAG_NAME] !== void 0) {
  350. if (rawTextElement.test(match[TAG_NAME])) {
  351. rawTextEndRegex = new RegExp(`</${match[TAG_NAME]}`, "g");
  352. }
  353. regex = tagEndRegex;
  354. } else if (match[DYNAMIC_TAG_NAME] !== void 0) {
  355. if (DEV_MODE) {
  356. throw new Error("Bindings in tag names are not supported. Please use static templates instead. See https://lit.dev/docs/templates/expressions/#static-expressions");
  357. }
  358. regex = tagEndRegex;
  359. }
  360. } else if (regex === tagEndRegex) {
  361. if (match[ENTIRE_MATCH] === ">") {
  362. regex = rawTextEndRegex !== null && rawTextEndRegex !== void 0 ? rawTextEndRegex : textEndRegex;
  363. attrNameEndIndex = -1;
  364. } else if (match[ATTRIBUTE_NAME] === void 0) {
  365. attrNameEndIndex = -2;
  366. } else {
  367. attrNameEndIndex = regex.lastIndex - match[SPACES_AND_EQUALS].length;
  368. attrName = match[ATTRIBUTE_NAME];
  369. regex = match[QUOTE_CHAR] === void 0 ? tagEndRegex : match[QUOTE_CHAR] === '"' ? doubleQuoteAttrEndRegex : singleQuoteAttrEndRegex;
  370. }
  371. } else if (regex === doubleQuoteAttrEndRegex || regex === singleQuoteAttrEndRegex) {
  372. regex = tagEndRegex;
  373. } else if (regex === commentEndRegex || regex === comment2EndRegex) {
  374. regex = textEndRegex;
  375. } else {
  376. regex = tagEndRegex;
  377. rawTextEndRegex = void 0;
  378. }
  379. }
  380. if (DEV_MODE) {
  381. console.assert(attrNameEndIndex === -1 || regex === tagEndRegex || regex === singleQuoteAttrEndRegex || regex === doubleQuoteAttrEndRegex, "unexpected parse state B");
  382. }
  383. const end = regex === tagEndRegex && strings[i + 1].startsWith("/>") ? " " : "";
  384. html2 += regex === textEndRegex ? s + nodeMarker : attrNameEndIndex >= 0 ? (attrNames.push(attrName), s.slice(0, attrNameEndIndex) + boundAttributeSuffix + s.slice(attrNameEndIndex)) + marker + end : s + marker + (attrNameEndIndex === -2 ? (attrNames.push(void 0), i) : end);
  385. }
  386. const htmlResult = html2 + (strings[l] || "<?>") + (type === SVG_RESULT ? "</svg>" : "");
  387. if (!Array.isArray(strings) || !strings.hasOwnProperty("raw")) {
  388. let message = "invalid template strings array";
  389. if (DEV_MODE) {
  390. message = `
  391. Internal Error: expected template strings to be an array
  392. with a 'raw' field. Faking a template strings array by
  393. calling html or svg like an ordinary function is effectively
  394. the same as calling unsafeHtml and can lead to major security
  395. issues, e.g. opening your code up to XSS attacks.
  396.  
  397. If you're using the html or svg tagged template functions normally
  398. and still seeing this error, please file a bug at
  399. https://github.com/lit/lit/issues/new?template=bug_report.md
  400. and include information about your build tooling, if any.
  401. `.trim().replace(/\n */g, "\n");
  402. }
  403. throw new Error(message);
  404. }
  405. return [
  406. policy !== void 0 ? policy.createHTML(htmlResult) : htmlResult,
  407. attrNames
  408. ];
  409. };
  410. var Template = class _Template {
  411. constructor({ strings, ["_$litType$"]: type }, options) {
  412. this.parts = [];
  413. let node;
  414. let nodeIndex = 0;
  415. let attrNameIndex = 0;
  416. const partCount = strings.length - 1;
  417. const parts = this.parts;
  418. const [html2, attrNames] = getTemplateHtml(strings, type);
  419. this.el = _Template.createElement(html2, options);
  420. walker.currentNode = this.el.content;
  421. if (type === SVG_RESULT) {
  422. const content = this.el.content;
  423. const svgElement = content.firstChild;
  424. svgElement.remove();
  425. content.append(...svgElement.childNodes);
  426. }
  427. while ((node = walker.nextNode()) !== null && parts.length < partCount) {
  428. if (node.nodeType === 1) {
  429. if (DEV_MODE) {
  430. const tag2 = node.localName;
  431. if (/^(?:textarea|template)$/i.test(tag2) && node.innerHTML.includes(marker)) {
  432. const m = `Expressions are not supported inside \`${tag2}\` elements. See https://lit.dev/msg/expression-in-${tag2} for more information.`;
  433. if (tag2 === "template") {
  434. throw new Error(m);
  435. } else
  436. issueWarning("", m);
  437. }
  438. }
  439. if (node.hasAttributes()) {
  440. const attrsToRemove = [];
  441. for (const name of node.getAttributeNames()) {
  442. if (name.endsWith(boundAttributeSuffix) || name.startsWith(marker)) {
  443. const realName = attrNames[attrNameIndex++];
  444. attrsToRemove.push(name);
  445. if (realName !== void 0) {
  446. const value = node.getAttribute(realName.toLowerCase() + boundAttributeSuffix);
  447. const statics = value.split(marker);
  448. const m = /([.?@])?(.*)/.exec(realName);
  449. parts.push({
  450. type: ATTRIBUTE_PART,
  451. index: nodeIndex,
  452. name: m[2],
  453. strings: statics,
  454. ctor: m[1] === "." ? PropertyPart : m[1] === "?" ? BooleanAttributePart : m[1] === "@" ? EventPart : AttributePart
  455. });
  456. } else {
  457. parts.push({
  458. type: ELEMENT_PART,
  459. index: nodeIndex
  460. });
  461. }
  462. }
  463. }
  464. for (const name of attrsToRemove) {
  465. node.removeAttribute(name);
  466. }
  467. }
  468. if (rawTextElement.test(node.tagName)) {
  469. const strings2 = node.textContent.split(marker);
  470. const lastIndex = strings2.length - 1;
  471. if (lastIndex > 0) {
  472. node.textContent = trustedTypes ? trustedTypes.emptyScript : "";
  473. for (let i = 0; i < lastIndex; i++) {
  474. node.append(strings2[i], createMarker());
  475. walker.nextNode();
  476. parts.push({ type: CHILD_PART, index: ++nodeIndex });
  477. }
  478. node.append(strings2[lastIndex], createMarker());
  479. }
  480. }
  481. } else if (node.nodeType === 8) {
  482. const data = node.data;
  483. if (data === markerMatch) {
  484. parts.push({ type: CHILD_PART, index: nodeIndex });
  485. } else {
  486. let i = -1;
  487. while ((i = node.data.indexOf(marker, i + 1)) !== -1) {
  488. parts.push({ type: COMMENT_PART, index: nodeIndex });
  489. i += marker.length - 1;
  490. }
  491. }
  492. }
  493. nodeIndex++;
  494. }
  495. debugLogEvent === null || debugLogEvent === void 0 ? void 0 : debugLogEvent({
  496. kind: "template prep",
  497. template: this,
  498. clonableTemplate: this.el,
  499. parts: this.parts,
  500. strings
  501. });
  502. }
  503. // Overridden via `litHtmlPolyfillSupport` to provide platform support.
  504. /** @nocollapse */
  505. static createElement(html2, _options) {
  506. const el = d.createElement("template");
  507. el.innerHTML = html2;
  508. return el;
  509. }
  510. };
  511. function resolveDirective(part, value, parent = part, attributeIndex) {
  512. var _a2, _b2, _c2;
  513. var _d2;
  514. if (value === noChange) {
  515. return value;
  516. }
  517. let currentDirective = attributeIndex !== void 0 ? (_a2 = parent.__directives) === null || _a2 === void 0 ? void 0 : _a2[attributeIndex] : parent.__directive;
  518. const nextDirectiveConstructor = isPrimitive(value) ? void 0 : (
  519. // This property needs to remain unminified.
  520. value["_$litDirective$"]
  521. );
  522. if ((currentDirective === null || currentDirective === void 0 ? void 0 : currentDirective.constructor) !== nextDirectiveConstructor) {
  523. (_b2 = currentDirective === null || currentDirective === void 0 ? void 0 : currentDirective["_$notifyDirectiveConnectionChanged"]) === null || _b2 === void 0 ? void 0 : _b2.call(currentDirective, false);
  524. if (nextDirectiveConstructor === void 0) {
  525. currentDirective = void 0;
  526. } else {
  527. currentDirective = new nextDirectiveConstructor(part);
  528. currentDirective._$initialize(part, parent, attributeIndex);
  529. }
  530. if (attributeIndex !== void 0) {
  531. ((_c2 = (_d2 = parent).__directives) !== null && _c2 !== void 0 ? _c2 : _d2.__directives = [])[attributeIndex] = currentDirective;
  532. } else {
  533. parent.__directive = currentDirective;
  534. }
  535. }
  536. if (currentDirective !== void 0) {
  537. value = resolveDirective(part, currentDirective._$resolve(part, value.values), currentDirective, attributeIndex);
  538. }
  539. return value;
  540. }
  541. var TemplateInstance = class {
  542. constructor(template, parent) {
  543. this._$parts = [];
  544. this._$disconnectableChildren = void 0;
  545. this._$template = template;
  546. this._$parent = parent;
  547. }
  548. // Called by ChildPart parentNode getter
  549. get parentNode() {
  550. return this._$parent.parentNode;
  551. }
  552. // See comment in Disconnectable interface for why this is a getter
  553. get _$isConnected() {
  554. return this._$parent._$isConnected;
  555. }
  556. // This method is separate from the constructor because we need to return a
  557. // DocumentFragment and we don't want to hold onto it with an instance field.
  558. _clone(options) {
  559. var _a2;
  560. const { el: { content }, parts } = this._$template;
  561. const fragment = ((_a2 = options === null || options === void 0 ? void 0 : options.creationScope) !== null && _a2 !== void 0 ? _a2 : d).importNode(content, true);
  562. walker.currentNode = fragment;
  563. let node = walker.nextNode();
  564. let nodeIndex = 0;
  565. let partIndex = 0;
  566. let templatePart = parts[0];
  567. while (templatePart !== void 0) {
  568. if (nodeIndex === templatePart.index) {
  569. let part;
  570. if (templatePart.type === CHILD_PART) {
  571. part = new ChildPart(node, node.nextSibling, this, options);
  572. } else if (templatePart.type === ATTRIBUTE_PART) {
  573. part = new templatePart.ctor(node, templatePart.name, templatePart.strings, this, options);
  574. } else if (templatePart.type === ELEMENT_PART) {
  575. part = new ElementPart(node, this, options);
  576. }
  577. this._$parts.push(part);
  578. templatePart = parts[++partIndex];
  579. }
  580. if (nodeIndex !== (templatePart === null || templatePart === void 0 ? void 0 : templatePart.index)) {
  581. node = walker.nextNode();
  582. nodeIndex++;
  583. }
  584. }
  585. return fragment;
  586. }
  587. _update(values) {
  588. let i = 0;
  589. for (const part of this._$parts) {
  590. if (part !== void 0) {
  591. debugLogEvent === null || debugLogEvent === void 0 ? void 0 : debugLogEvent({
  592. kind: "set part",
  593. part,
  594. value: values[i],
  595. valueIndex: i,
  596. values,
  597. templateInstance: this
  598. });
  599. if (part.strings !== void 0) {
  600. part._$setValue(values, part, i);
  601. i += part.strings.length - 2;
  602. } else {
  603. part._$setValue(values[i]);
  604. }
  605. }
  606. i++;
  607. }
  608. }
  609. };
  610. var ChildPart = class _ChildPart {
  611. constructor(startNode, endNode, parent, options) {
  612. var _a2;
  613. this.type = CHILD_PART;
  614. this._$committedValue = nothing;
  615. this._$disconnectableChildren = void 0;
  616. this._$startNode = startNode;
  617. this._$endNode = endNode;
  618. this._$parent = parent;
  619. this.options = options;
  620. this.__isConnected = (_a2 = options === null || options === void 0 ? void 0 : options.isConnected) !== null && _a2 !== void 0 ? _a2 : true;
  621. if (ENABLE_EXTRA_SECURITY_HOOKS) {
  622. this._textSanitizer = void 0;
  623. }
  624. }
  625. // See comment in Disconnectable interface for why this is a getter
  626. get _$isConnected() {
  627. var _a2, _b2;
  628. return (_b2 = (_a2 = this._$parent) === null || _a2 === void 0 ? void 0 : _a2._$isConnected) !== null && _b2 !== void 0 ? _b2 : this.__isConnected;
  629. }
  630. /**
  631. * The parent node into which the part renders its content.
  632. *
  633. * A ChildPart's content consists of a range of adjacent child nodes of
  634. * `.parentNode`, possibly bordered by 'marker nodes' (`.startNode` and
  635. * `.endNode`).
  636. *
  637. * - If both `.startNode` and `.endNode` are non-null, then the part's content
  638. * consists of all siblings between `.startNode` and `.endNode`, exclusively.
  639. *
  640. * - If `.startNode` is non-null but `.endNode` is null, then the part's
  641. * content consists of all siblings following `.startNode`, up to and
  642. * including the last child of `.parentNode`. If `.endNode` is non-null, then
  643. * `.startNode` will always be non-null.
  644. *
  645. * - If both `.endNode` and `.startNode` are null, then the part's content
  646. * consists of all child nodes of `.parentNode`.
  647. */
  648. get parentNode() {
  649. let parentNode = wrap(this._$startNode).parentNode;
  650. const parent = this._$parent;
  651. if (parent !== void 0 && (parentNode === null || parentNode === void 0 ? void 0 : parentNode.nodeType) === 11) {
  652. parentNode = parent.parentNode;
  653. }
  654. return parentNode;
  655. }
  656. /**
  657. * The part's leading marker node, if any. See `.parentNode` for more
  658. * information.
  659. */
  660. get startNode() {
  661. return this._$startNode;
  662. }
  663. /**
  664. * The part's trailing marker node, if any. See `.parentNode` for more
  665. * information.
  666. */
  667. get endNode() {
  668. return this._$endNode;
  669. }
  670. _$setValue(value, directiveParent = this) {
  671. var _a2;
  672. if (DEV_MODE && this.parentNode === null) {
  673. throw new Error(`This \`ChildPart\` has no \`parentNode\` and therefore cannot accept a value. This likely means the element containing the part was manipulated in an unsupported way outside of Lit's control such that the part's marker nodes were ejected from DOM. For example, setting the element's \`innerHTML\` or \`textContent\` can do this.`);
  674. }
  675. value = resolveDirective(this, value, directiveParent);
  676. if (isPrimitive(value)) {
  677. if (value === nothing || value == null || value === "") {
  678. if (this._$committedValue !== nothing) {
  679. debugLogEvent === null || debugLogEvent === void 0 ? void 0 : debugLogEvent({
  680. kind: "commit nothing to child",
  681. start: this._$startNode,
  682. end: this._$endNode,
  683. parent: this._$parent,
  684. options: this.options
  685. });
  686. this._$clear();
  687. }
  688. this._$committedValue = nothing;
  689. } else if (value !== this._$committedValue && value !== noChange) {
  690. this._commitText(value);
  691. }
  692. } else if (value["_$litType$"] !== void 0) {
  693. this._commitTemplateResult(value);
  694. } else if (value.nodeType !== void 0) {
  695. if (DEV_MODE && ((_a2 = this.options) === null || _a2 === void 0 ? void 0 : _a2.host) === value) {
  696. this._commitText(`[probable mistake: rendered a template's host in itself (commonly caused by writing \${this} in a template]`);
  697. console.warn(`Attempted to render the template host`, value, `inside itself. This is almost always a mistake, and in dev mode `, `we render some warning text. In production however, we'll `, `render it, which will usually result in an error, and sometimes `, `in the element disappearing from the DOM.`);
  698. return;
  699. }
  700. this._commitNode(value);
  701. } else if (isIterable(value)) {
  702. this._commitIterable(value);
  703. } else {
  704. this._commitText(value);
  705. }
  706. }
  707. _insert(node) {
  708. return wrap(wrap(this._$startNode).parentNode).insertBefore(node, this._$endNode);
  709. }
  710. _commitNode(value) {
  711. var _a2;
  712. if (this._$committedValue !== value) {
  713. this._$clear();
  714. if (ENABLE_EXTRA_SECURITY_HOOKS && sanitizerFactoryInternal !== noopSanitizer) {
  715. const parentNodeName = (_a2 = this._$startNode.parentNode) === null || _a2 === void 0 ? void 0 : _a2.nodeName;
  716. if (parentNodeName === "STYLE" || parentNodeName === "SCRIPT") {
  717. let message = "Forbidden";
  718. if (DEV_MODE) {
  719. if (parentNodeName === "STYLE") {
  720. message = `Lit does not support binding inside style nodes. This is a security risk, as style injection attacks can exfiltrate data and spoof UIs. Consider instead using css\`...\` literals to compose styles, and make do dynamic styling with css custom properties, ::parts, <slot>s, and by mutating the DOM rather than stylesheets.`;
  721. } else {
  722. message = `Lit does not support binding inside script nodes. This is a security risk, as it could allow arbitrary code execution.`;
  723. }
  724. }
  725. throw new Error(message);
  726. }
  727. }
  728. debugLogEvent === null || debugLogEvent === void 0 ? void 0 : debugLogEvent({
  729. kind: "commit node",
  730. start: this._$startNode,
  731. parent: this._$parent,
  732. value,
  733. options: this.options
  734. });
  735. this._$committedValue = this._insert(value);
  736. }
  737. }
  738. _commitText(value) {
  739. if (this._$committedValue !== nothing && isPrimitive(this._$committedValue)) {
  740. const node = wrap(this._$startNode).nextSibling;
  741. if (ENABLE_EXTRA_SECURITY_HOOKS) {
  742. if (this._textSanitizer === void 0) {
  743. this._textSanitizer = createSanitizer(node, "data", "property");
  744. }
  745. value = this._textSanitizer(value);
  746. }
  747. debugLogEvent === null || debugLogEvent === void 0 ? void 0 : debugLogEvent({
  748. kind: "commit text",
  749. node,
  750. value,
  751. options: this.options
  752. });
  753. node.data = value;
  754. } else {
  755. if (ENABLE_EXTRA_SECURITY_HOOKS) {
  756. const textNode = d.createTextNode("");
  757. this._commitNode(textNode);
  758. if (this._textSanitizer === void 0) {
  759. this._textSanitizer = createSanitizer(textNode, "data", "property");
  760. }
  761. value = this._textSanitizer(value);
  762. debugLogEvent === null || debugLogEvent === void 0 ? void 0 : debugLogEvent({
  763. kind: "commit text",
  764. node: textNode,
  765. value,
  766. options: this.options
  767. });
  768. textNode.data = value;
  769. } else {
  770. this._commitNode(d.createTextNode(value));
  771. debugLogEvent === null || debugLogEvent === void 0 ? void 0 : debugLogEvent({
  772. kind: "commit text",
  773. node: wrap(this._$startNode).nextSibling,
  774. value,
  775. options: this.options
  776. });
  777. }
  778. }
  779. this._$committedValue = value;
  780. }
  781. _commitTemplateResult(result) {
  782. var _a2;
  783. const { values, ["_$litType$"]: type } = result;
  784. const template = typeof type === "number" ? this._$getTemplate(result) : (type.el === void 0 && (type.el = Template.createElement(type.h, this.options)), type);
  785. if (((_a2 = this._$committedValue) === null || _a2 === void 0 ? void 0 : _a2._$template) === template) {
  786. debugLogEvent === null || debugLogEvent === void 0 ? void 0 : debugLogEvent({
  787. kind: "template updating",
  788. template,
  789. instance: this._$committedValue,
  790. parts: this._$committedValue._$parts,
  791. options: this.options,
  792. values
  793. });
  794. this._$committedValue._update(values);
  795. } else {
  796. const instance = new TemplateInstance(template, this);
  797. const fragment = instance._clone(this.options);
  798. debugLogEvent === null || debugLogEvent === void 0 ? void 0 : debugLogEvent({
  799. kind: "template instantiated",
  800. template,
  801. instance,
  802. parts: instance._$parts,
  803. options: this.options,
  804. fragment,
  805. values
  806. });
  807. instance._update(values);
  808. debugLogEvent === null || debugLogEvent === void 0 ? void 0 : debugLogEvent({
  809. kind: "template instantiated and updated",
  810. template,
  811. instance,
  812. parts: instance._$parts,
  813. options: this.options,
  814. fragment,
  815. values
  816. });
  817. this._commitNode(fragment);
  818. this._$committedValue = instance;
  819. }
  820. }
  821. // Overridden via `litHtmlPolyfillSupport` to provide platform support.
  822. /** @internal */
  823. _$getTemplate(result) {
  824. let template = templateCache.get(result.strings);
  825. if (template === void 0) {
  826. templateCache.set(result.strings, template = new Template(result));
  827. }
  828. return template;
  829. }
  830. _commitIterable(value) {
  831. if (!isArray(this._$committedValue)) {
  832. this._$committedValue = [];
  833. this._$clear();
  834. }
  835. const itemParts = this._$committedValue;
  836. let partIndex = 0;
  837. let itemPart;
  838. for (const item of value) {
  839. if (partIndex === itemParts.length) {
  840. itemParts.push(itemPart = new _ChildPart(this._insert(createMarker()), this._insert(createMarker()), this, this.options));
  841. } else {
  842. itemPart = itemParts[partIndex];
  843. }
  844. itemPart._$setValue(item);
  845. partIndex++;
  846. }
  847. if (partIndex < itemParts.length) {
  848. this._$clear(itemPart && wrap(itemPart._$endNode).nextSibling, partIndex);
  849. itemParts.length = partIndex;
  850. }
  851. }
  852. /**
  853. * Removes the nodes contained within this Part from the DOM.
  854. *
  855. * @param start Start node to clear from, for clearing a subset of the part's
  856. * DOM (used when truncating iterables)
  857. * @param from When `start` is specified, the index within the iterable from
  858. * which ChildParts are being removed, used for disconnecting directives in
  859. * those Parts.
  860. *
  861. * @internal
  862. */
  863. _$clear(start = wrap(this._$startNode).nextSibling, from) {
  864. var _a2;
  865. (_a2 = this._$notifyConnectionChanged) === null || _a2 === void 0 ? void 0 : _a2.call(this, false, true, from);
  866. while (start && start !== this._$endNode) {
  867. const n = wrap(start).nextSibling;
  868. wrap(start).remove();
  869. start = n;
  870. }
  871. }
  872. /**
  873. * Implementation of RootPart's `isConnected`. Note that this metod
  874. * should only be called on `RootPart`s (the `ChildPart` returned from a
  875. * top-level `render()` call). It has no effect on non-root ChildParts.
  876. * @param isConnected Whether to set
  877. * @internal
  878. */
  879. setConnected(isConnected) {
  880. var _a2;
  881. if (this._$parent === void 0) {
  882. this.__isConnected = isConnected;
  883. (_a2 = this._$notifyConnectionChanged) === null || _a2 === void 0 ? void 0 : _a2.call(this, isConnected);
  884. } else if (DEV_MODE) {
  885. throw new Error("part.setConnected() may only be called on a RootPart returned from render().");
  886. }
  887. }
  888. };
  889. var AttributePart = class {
  890. constructor(element, name, strings, parent, options) {
  891. this.type = ATTRIBUTE_PART;
  892. this._$committedValue = nothing;
  893. this._$disconnectableChildren = void 0;
  894. this.element = element;
  895. this.name = name;
  896. this._$parent = parent;
  897. this.options = options;
  898. if (strings.length > 2 || strings[0] !== "" || strings[1] !== "") {
  899. this._$committedValue = new Array(strings.length - 1).fill(new String());
  900. this.strings = strings;
  901. } else {
  902. this._$committedValue = nothing;
  903. }
  904. if (ENABLE_EXTRA_SECURITY_HOOKS) {
  905. this._sanitizer = void 0;
  906. }
  907. }
  908. get tagName() {
  909. return this.element.tagName;
  910. }
  911. // See comment in Disconnectable interface for why this is a getter
  912. get _$isConnected() {
  913. return this._$parent._$isConnected;
  914. }
  915. /**
  916. * Sets the value of this part by resolving the value from possibly multiple
  917. * values and static strings and committing it to the DOM.
  918. * If this part is single-valued, `this._strings` will be undefined, and the
  919. * method will be called with a single value argument. If this part is
  920. * multi-value, `this._strings` will be defined, and the method is called
  921. * with the value array of the part's owning TemplateInstance, and an offset
  922. * into the value array from which the values should be read.
  923. * This method is overloaded this way to eliminate short-lived array slices
  924. * of the template instance values, and allow a fast-path for single-valued
  925. * parts.
  926. *
  927. * @param value The part value, or an array of values for multi-valued parts
  928. * @param valueIndex the index to start reading values from. `undefined` for
  929. * single-valued parts
  930. * @param noCommit causes the part to not commit its value to the DOM. Used
  931. * in hydration to prime attribute parts with their first-rendered value,
  932. * but not set the attribute, and in SSR to no-op the DOM operation and
  933. * capture the value for serialization.
  934. *
  935. * @internal
  936. */
  937. _$setValue(value, directiveParent = this, valueIndex, noCommit) {
  938. const strings = this.strings;
  939. let change = false;
  940. if (strings === void 0) {
  941. value = resolveDirective(this, value, directiveParent, 0);
  942. change = !isPrimitive(value) || value !== this._$committedValue && value !== noChange;
  943. if (change) {
  944. this._$committedValue = value;
  945. }
  946. } else {
  947. const values = value;
  948. value = strings[0];
  949. let i, v;
  950. for (i = 0; i < strings.length - 1; i++) {
  951. v = resolveDirective(this, values[valueIndex + i], directiveParent, i);
  952. if (v === noChange) {
  953. v = this._$committedValue[i];
  954. }
  955. change || (change = !isPrimitive(v) || v !== this._$committedValue[i]);
  956. if (v === nothing) {
  957. value = nothing;
  958. } else if (value !== nothing) {
  959. value += (v !== null && v !== void 0 ? v : "") + strings[i + 1];
  960. }
  961. this._$committedValue[i] = v;
  962. }
  963. }
  964. if (change && !noCommit) {
  965. this._commitValue(value);
  966. }
  967. }
  968. /** @internal */
  969. _commitValue(value) {
  970. if (value === nothing) {
  971. wrap(this.element).removeAttribute(this.name);
  972. } else {
  973. if (ENABLE_EXTRA_SECURITY_HOOKS) {
  974. if (this._sanitizer === void 0) {
  975. this._sanitizer = sanitizerFactoryInternal(this.element, this.name, "attribute");
  976. }
  977. value = this._sanitizer(value !== null && value !== void 0 ? value : "");
  978. }
  979. debugLogEvent === null || debugLogEvent === void 0 ? void 0 : debugLogEvent({
  980. kind: "commit attribute",
  981. element: this.element,
  982. name: this.name,
  983. value,
  984. options: this.options
  985. });
  986. wrap(this.element).setAttribute(this.name, value !== null && value !== void 0 ? value : "");
  987. }
  988. }
  989. };
  990. var PropertyPart = class extends AttributePart {
  991. constructor() {
  992. super(...arguments);
  993. this.type = PROPERTY_PART;
  994. }
  995. /** @internal */
  996. _commitValue(value) {
  997. if (ENABLE_EXTRA_SECURITY_HOOKS) {
  998. if (this._sanitizer === void 0) {
  999. this._sanitizer = sanitizerFactoryInternal(this.element, this.name, "property");
  1000. }
  1001. value = this._sanitizer(value);
  1002. }
  1003. debugLogEvent === null || debugLogEvent === void 0 ? void 0 : debugLogEvent({
  1004. kind: "commit property",
  1005. element: this.element,
  1006. name: this.name,
  1007. value,
  1008. options: this.options
  1009. });
  1010. this.element[this.name] = value === nothing ? void 0 : value;
  1011. }
  1012. };
  1013. var emptyStringForBooleanAttribute = trustedTypes ? trustedTypes.emptyScript : "";
  1014. var BooleanAttributePart = class extends AttributePart {
  1015. constructor() {
  1016. super(...arguments);
  1017. this.type = BOOLEAN_ATTRIBUTE_PART;
  1018. }
  1019. /** @internal */
  1020. _commitValue(value) {
  1021. debugLogEvent === null || debugLogEvent === void 0 ? void 0 : debugLogEvent({
  1022. kind: "commit boolean attribute",
  1023. element: this.element,
  1024. name: this.name,
  1025. value: !!(value && value !== nothing),
  1026. options: this.options
  1027. });
  1028. if (value && value !== nothing) {
  1029. wrap(this.element).setAttribute(this.name, emptyStringForBooleanAttribute);
  1030. } else {
  1031. wrap(this.element).removeAttribute(this.name);
  1032. }
  1033. }
  1034. };
  1035. var EventPart = class extends AttributePart {
  1036. constructor(element, name, strings, parent, options) {
  1037. super(element, name, strings, parent, options);
  1038. this.type = EVENT_PART;
  1039. if (DEV_MODE && this.strings !== void 0) {
  1040. throw new Error(`A \`<${element.localName}>\` has a \`@${name}=...\` listener with invalid content. Event listeners in templates must have exactly one expression and no surrounding text.`);
  1041. }
  1042. }
  1043. // EventPart does not use the base _$setValue/_resolveValue implementation
  1044. // since the dirty checking is more complex
  1045. /** @internal */
  1046. _$setValue(newListener, directiveParent = this) {
  1047. var _a2;
  1048. newListener = (_a2 = resolveDirective(this, newListener, directiveParent, 0)) !== null && _a2 !== void 0 ? _a2 : nothing;
  1049. if (newListener === noChange) {
  1050. return;
  1051. }
  1052. const oldListener = this._$committedValue;
  1053. const shouldRemoveListener = newListener === nothing && oldListener !== nothing || newListener.capture !== oldListener.capture || newListener.once !== oldListener.once || newListener.passive !== oldListener.passive;
  1054. const shouldAddListener = newListener !== nothing && (oldListener === nothing || shouldRemoveListener);
  1055. debugLogEvent === null || debugLogEvent === void 0 ? void 0 : debugLogEvent({
  1056. kind: "commit event listener",
  1057. element: this.element,
  1058. name: this.name,
  1059. value: newListener,
  1060. options: this.options,
  1061. removeListener: shouldRemoveListener,
  1062. addListener: shouldAddListener,
  1063. oldListener
  1064. });
  1065. if (shouldRemoveListener) {
  1066. this.element.removeEventListener(this.name, this, oldListener);
  1067. }
  1068. if (shouldAddListener) {
  1069. this.element.addEventListener(this.name, this, newListener);
  1070. }
  1071. this._$committedValue = newListener;
  1072. }
  1073. handleEvent(event) {
  1074. var _a2, _b2;
  1075. if (typeof this._$committedValue === "function") {
  1076. this._$committedValue.call((_b2 = (_a2 = this.options) === null || _a2 === void 0 ? void 0 : _a2.host) !== null && _b2 !== void 0 ? _b2 : this.element, event);
  1077. } else {
  1078. this._$committedValue.handleEvent(event);
  1079. }
  1080. }
  1081. };
  1082. var ElementPart = class {
  1083. constructor(element, parent, options) {
  1084. this.element = element;
  1085. this.type = ELEMENT_PART;
  1086. this._$disconnectableChildren = void 0;
  1087. this._$parent = parent;
  1088. this.options = options;
  1089. }
  1090. // See comment in Disconnectable interface for why this is a getter
  1091. get _$isConnected() {
  1092. return this._$parent._$isConnected;
  1093. }
  1094. _$setValue(value) {
  1095. debugLogEvent === null || debugLogEvent === void 0 ? void 0 : debugLogEvent({
  1096. kind: "commit to element binding",
  1097. element: this.element,
  1098. value,
  1099. options: this.options
  1100. });
  1101. resolveDirective(this, value);
  1102. }
  1103. };
  1104. var polyfillSupport = DEV_MODE ? global2.litHtmlPolyfillSupportDevMode : global2.litHtmlPolyfillSupport;
  1105. polyfillSupport === null || polyfillSupport === void 0 ? void 0 : polyfillSupport(Template, ChildPart);
  1106. ((_d = global2.litHtmlVersions) !== null && _d !== void 0 ? _d : global2.litHtmlVersions = []).push("2.7.3");
  1107. if (DEV_MODE && global2.litHtmlVersions.length > 1) {
  1108. issueWarning("multiple-versions", `Multiple versions of Lit loaded. Loading multiple versions is not recommended.`);
  1109. }
  1110. var render = (value, container, options) => {
  1111. var _a2, _b2;
  1112. if (DEV_MODE && container == null) {
  1113. throw new TypeError(`The container to render into may not be ${container}`);
  1114. }
  1115. const renderId = DEV_MODE ? debugLogRenderId++ : 0;
  1116. const partOwnerNode = (_a2 = options === null || options === void 0 ? void 0 : options.renderBefore) !== null && _a2 !== void 0 ? _a2 : container;
  1117. let part = partOwnerNode["_$litPart$"];
  1118. debugLogEvent === null || debugLogEvent === void 0 ? void 0 : debugLogEvent({
  1119. kind: "begin render",
  1120. id: renderId,
  1121. value,
  1122. container,
  1123. options,
  1124. part
  1125. });
  1126. if (part === void 0) {
  1127. const endNode = (_b2 = options === null || options === void 0 ? void 0 : options.renderBefore) !== null && _b2 !== void 0 ? _b2 : null;
  1128. partOwnerNode["_$litPart$"] = part = new ChildPart(container.insertBefore(createMarker(), endNode), endNode, void 0, options !== null && options !== void 0 ? options : {});
  1129. }
  1130. part._$setValue(value);
  1131. debugLogEvent === null || debugLogEvent === void 0 ? void 0 : debugLogEvent({
  1132. kind: "end render",
  1133. id: renderId,
  1134. value,
  1135. container,
  1136. options,
  1137. part
  1138. });
  1139. return part;
  1140. };
  1141. if (ENABLE_EXTRA_SECURITY_HOOKS) {
  1142. render.setSanitizer = setSanitizer;
  1143. render.createSanitizer = createSanitizer;
  1144. if (DEV_MODE) {
  1145. render._testOnlyClearSanitizerFactoryDoNotCallOrElse = _testOnlyClearSanitizerFactoryDoNotCallOrElse;
  1146. }
  1147. }
  1148.  
  1149. // src/utils/compare.ts
  1150. function compare(a, b) {
  1151. if (a > b) {
  1152. return 1;
  1153. }
  1154. if (a < b) {
  1155. return -1;
  1156. }
  1157. return 0;
  1158. }
  1159.  
  1160. // node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_freeGlobal.js
  1161. var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
  1162. var freeGlobal_default = freeGlobal;
  1163.  
  1164. // node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_root.js
  1165. var freeSelf = typeof self == "object" && self && self.Object === Object && self;
  1166. var root = freeGlobal_default || freeSelf || Function("return this")();
  1167. var root_default = root;
  1168.  
  1169. // node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_Symbol.js
  1170. var Symbol2 = root_default.Symbol;
  1171. var Symbol_default = Symbol2;
  1172.  
  1173. // node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_getRawTag.js
  1174. var objectProto = Object.prototype;
  1175. var hasOwnProperty = objectProto.hasOwnProperty;
  1176. var nativeObjectToString = objectProto.toString;
  1177. var symToStringTag = Symbol_default ? Symbol_default.toStringTag : void 0;
  1178. function getRawTag(value) {
  1179. var isOwn = hasOwnProperty.call(value, symToStringTag), tag2 = value[symToStringTag];
  1180. try {
  1181. value[symToStringTag] = void 0;
  1182. var unmasked = true;
  1183. } catch (e) {
  1184. }
  1185. var result = nativeObjectToString.call(value);
  1186. if (unmasked) {
  1187. if (isOwn) {
  1188. value[symToStringTag] = tag2;
  1189. } else {
  1190. delete value[symToStringTag];
  1191. }
  1192. }
  1193. return result;
  1194. }
  1195. var getRawTag_default = getRawTag;
  1196.  
  1197. // node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_objectToString.js
  1198. var objectProto2 = Object.prototype;
  1199. var nativeObjectToString2 = objectProto2.toString;
  1200. function objectToString(value) {
  1201. return nativeObjectToString2.call(value);
  1202. }
  1203. var objectToString_default = objectToString;
  1204.  
  1205. // node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_baseGetTag.js
  1206. var nullTag = "[object Null]";
  1207. var undefinedTag = "[object Undefined]";
  1208. var symToStringTag2 = Symbol_default ? Symbol_default.toStringTag : void 0;
  1209. function baseGetTag(value) {
  1210. if (value == null) {
  1211. return value === void 0 ? undefinedTag : nullTag;
  1212. }
  1213. return symToStringTag2 && symToStringTag2 in Object(value) ? getRawTag_default(value) : objectToString_default(value);
  1214. }
  1215. var baseGetTag_default = baseGetTag;
  1216.  
  1217. // node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isObjectLike.js
  1218. function isObjectLike(value) {
  1219. return value != null && typeof value == "object";
  1220. }
  1221. var isObjectLike_default = isObjectLike;
  1222.  
  1223. // node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isSymbol.js
  1224. var symbolTag = "[object Symbol]";
  1225. function isSymbol(value) {
  1226. return typeof value == "symbol" || isObjectLike_default(value) && baseGetTag_default(value) == symbolTag;
  1227. }
  1228. var isSymbol_default = isSymbol;
  1229.  
  1230. // node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_trimmedEndIndex.js
  1231. var reWhitespace = /\s/;
  1232. function trimmedEndIndex(string) {
  1233. var index = string.length;
  1234. while (index-- && reWhitespace.test(string.charAt(index))) {
  1235. }
  1236. return index;
  1237. }
  1238. var trimmedEndIndex_default = trimmedEndIndex;
  1239.  
  1240. // node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_baseTrim.js
  1241. var reTrimStart = /^\s+/;
  1242. function baseTrim(string) {
  1243. return string ? string.slice(0, trimmedEndIndex_default(string) + 1).replace(reTrimStart, "") : string;
  1244. }
  1245. var baseTrim_default = baseTrim;
  1246.  
  1247. // node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isObject.js
  1248. function isObject(value) {
  1249. var type = typeof value;
  1250. return value != null && (type == "object" || type == "function");
  1251. }
  1252. var isObject_default = isObject;
  1253.  
  1254. // node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/toNumber.js
  1255. var NAN = 0 / 0;
  1256. var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
  1257. var reIsBinary = /^0b[01]+$/i;
  1258. var reIsOctal = /^0o[0-7]+$/i;
  1259. var freeParseInt = parseInt;
  1260. function toNumber(value) {
  1261. if (typeof value == "number") {
  1262. return value;
  1263. }
  1264. if (isSymbol_default(value)) {
  1265. return NAN;
  1266. }
  1267. if (isObject_default(value)) {
  1268. var other = typeof value.valueOf == "function" ? value.valueOf() : value;
  1269. value = isObject_default(other) ? other + "" : other;
  1270. }
  1271. if (typeof value != "string") {
  1272. return value === 0 ? value : +value;
  1273. }
  1274. value = baseTrim_default(value);
  1275. var isBinary = reIsBinary.test(value);
  1276. return isBinary || reIsOctal.test(value) ? freeParseInt(value.slice(2), isBinary ? 2 : 8) : reIsBadHex.test(value) ? NAN : +value;
  1277. }
  1278. var toNumber_default = toNumber;
  1279.  
  1280. // node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_overArg.js
  1281. function overArg(func, transform) {
  1282. return function(arg) {
  1283. return func(transform(arg));
  1284. };
  1285. }
  1286. var overArg_default = overArg;
  1287.  
  1288. // node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_getPrototype.js
  1289. var getPrototype = overArg_default(Object.getPrototypeOf, Object);
  1290. var getPrototype_default = getPrototype;
  1291.  
  1292. // node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isPlainObject.js
  1293. var objectTag = "[object Object]";
  1294. var funcProto = Function.prototype;
  1295. var objectProto3 = Object.prototype;
  1296. var funcToString = funcProto.toString;
  1297. var hasOwnProperty2 = objectProto3.hasOwnProperty;
  1298. var objectCtorString = funcToString.call(Object);
  1299. function isPlainObject(value) {
  1300. if (!isObjectLike_default(value) || baseGetTag_default(value) != objectTag) {
  1301. return false;
  1302. }
  1303. var proto = getPrototype_default(value);
  1304. if (proto === null) {
  1305. return true;
  1306. }
  1307. var Ctor = hasOwnProperty2.call(proto, "constructor") && proto.constructor;
  1308. return typeof Ctor == "function" && Ctor instanceof Ctor && funcToString.call(Ctor) == objectCtorString;
  1309. }
  1310. var isPlainObject_default = isPlainObject;
  1311.  
  1312. // node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/now.js
  1313. var now = function() {
  1314. return root_default.Date.now();
  1315. };
  1316. var now_default = now;
  1317.  
  1318. // node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/debounce.js
  1319. var FUNC_ERROR_TEXT = "Expected a function";
  1320. var nativeMax = Math.max;
  1321. var nativeMin = Math.min;
  1322. function debounce(func, wait, options) {
  1323. var lastArgs, lastThis, maxWait, result, timerId, lastCallTime, lastInvokeTime = 0, leading = false, maxing = false, trailing = true;
  1324. if (typeof func != "function") {
  1325. throw new TypeError(FUNC_ERROR_TEXT);
  1326. }
  1327. wait = toNumber_default(wait) || 0;
  1328. if (isObject_default(options)) {
  1329. leading = !!options.leading;
  1330. maxing = "maxWait" in options;
  1331. maxWait = maxing ? nativeMax(toNumber_default(options.maxWait) || 0, wait) : maxWait;
  1332. trailing = "trailing" in options ? !!options.trailing : trailing;
  1333. }
  1334. function invokeFunc(time) {
  1335. var args = lastArgs, thisArg = lastThis;
  1336. lastArgs = lastThis = void 0;
  1337. lastInvokeTime = time;
  1338. result = func.apply(thisArg, args);
  1339. return result;
  1340. }
  1341. function leadingEdge(time) {
  1342. lastInvokeTime = time;
  1343. timerId = setTimeout(timerExpired, wait);
  1344. return leading ? invokeFunc(time) : result;
  1345. }
  1346. function remainingWait(time) {
  1347. var timeSinceLastCall = time - lastCallTime, timeSinceLastInvoke = time - lastInvokeTime, timeWaiting = wait - timeSinceLastCall;
  1348. return maxing ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke) : timeWaiting;
  1349. }
  1350. function shouldInvoke(time) {
  1351. var timeSinceLastCall = time - lastCallTime, timeSinceLastInvoke = time - lastInvokeTime;
  1352. return lastCallTime === void 0 || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait;
  1353. }
  1354. function timerExpired() {
  1355. var time = now_default();
  1356. if (shouldInvoke(time)) {
  1357. return trailingEdge(time);
  1358. }
  1359. timerId = setTimeout(timerExpired, remainingWait(time));
  1360. }
  1361. function trailingEdge(time) {
  1362. timerId = void 0;
  1363. if (trailing && lastArgs) {
  1364. return invokeFunc(time);
  1365. }
  1366. lastArgs = lastThis = void 0;
  1367. return result;
  1368. }
  1369. function cancel() {
  1370. if (timerId !== void 0) {
  1371. clearTimeout(timerId);
  1372. }
  1373. lastInvokeTime = 0;
  1374. lastArgs = lastCallTime = lastThis = timerId = void 0;
  1375. }
  1376. function flush() {
  1377. return timerId === void 0 ? result : trailingEdge(now_default());
  1378. }
  1379. function debounced() {
  1380. var time = now_default(), isInvoking = shouldInvoke(time);
  1381. lastArgs = arguments;
  1382. lastThis = this;
  1383. lastCallTime = time;
  1384. if (isInvoking) {
  1385. if (timerId === void 0) {
  1386. return leadingEdge(lastCallTime);
  1387. }
  1388. if (maxing) {
  1389. clearTimeout(timerId);
  1390. timerId = setTimeout(timerExpired, wait);
  1391. return invokeFunc(lastCallTime);
  1392. }
  1393. }
  1394. if (timerId === void 0) {
  1395. timerId = setTimeout(timerExpired, wait);
  1396. }
  1397. return result;
  1398. }
  1399. debounced.cancel = cancel;
  1400. debounced.flush = flush;
  1401. return debounced;
  1402. }
  1403. var debounce_default = debounce;
  1404.  
  1405. // src/utils/growTextAreaHeight.ts
  1406. function growTextAreaHeight(el) {
  1407. const maxHeight = Math.min(window.innerHeight, el.scrollHeight);
  1408. if (el.scrollHeight > el.clientHeight && el.clientHeight < maxHeight) {
  1409. el.style.height = `${maxHeight}px`;
  1410. }
  1411. }
  1412.  
  1413. // src/utils/GMValue.ts
  1414. var GMValue = class {
  1415. constructor(key2, defaultValue) {
  1416. this.key = key2;
  1417. this.defaultValue = defaultValue;
  1418. __publicField(this, "value");
  1419. __publicField(this, "loadingCount", 0);
  1420. __publicField(this, "currentAction");
  1421. __publicField(this, "polling");
  1422. __publicField(this, "refresh", () => __async(this, null, function* () {
  1423. if (this.isLoading) {
  1424. yield this.currentAction;
  1425. return;
  1426. }
  1427. this.loadingCount += 1;
  1428. this.currentAction = (() => __async(this, null, function* () {
  1429. try {
  1430. const value = yield GM.getValue(this.key);
  1431. if (value != null) {
  1432. try {
  1433. this.value = JSON.parse(String(value));
  1434. } catch (e) {
  1435. this.value = void 0;
  1436. }
  1437. }
  1438. } finally {
  1439. this.loadingCount -= 1;
  1440. }
  1441. }))();
  1442. yield this.currentAction;
  1443. }));
  1444. __publicField(this, "flush", () => __async(this, null, function* () {
  1445. this.loadingCount += 1;
  1446. this.currentAction = (() => __async(this, null, function* () {
  1447. try {
  1448. if (this.value == null) {
  1449. yield GM.deleteValue(this.key);
  1450. } else {
  1451. yield GM.setValue(this.key, JSON.stringify(this.value));
  1452. }
  1453. } finally {
  1454. this.loadingCount -= 1;
  1455. }
  1456. }))();
  1457. yield this.currentAction;
  1458. }));
  1459. __publicField(this, "get", () => {
  1460. var _a2;
  1461. return (_a2 = this.value) != null ? _a2 : this.defaultValue();
  1462. });
  1463. __publicField(this, "set", (v) => {
  1464. this.value = v;
  1465. this.flush();
  1466. });
  1467. __publicField(this, "dispose", () => {
  1468. this.polling.dispose();
  1469. });
  1470. this.polling = new Polling({
  1471. update: () => this.refresh(),
  1472. scheduleNext: (update) => setTimeout(update, 500)
  1473. });
  1474. }
  1475. get isLoading() {
  1476. return this.loadingCount > 0;
  1477. }
  1478. };
  1479.  
  1480. // src/bilibili.com/models/blockedUsers.ts
  1481. var blockedUsers_default = new class {
  1482. constructor() {
  1483. __publicField(this, "value", new GMValue("blockedUsers@206ceed9-b514-4902-ad70-aa621fed5cd4", () => ({})));
  1484. __publicField(this, "has", (id) => {
  1485. return id in this.value.get();
  1486. });
  1487. __publicField(this, "get", (id) => {
  1488. const value = this.value.get()[id];
  1489. const { blockedAt: rawBlockedAt = 0, name = id } = typeof value === "boolean" ? {} : value != null ? value : {};
  1490. const blockedAt = new Date(rawBlockedAt);
  1491. return {
  1492. id,
  1493. blockedAt,
  1494. name,
  1495. idAsNumber: Number.parseInt(id, 10),
  1496. rawBlockedAt
  1497. };
  1498. });
  1499. __publicField(this, "distinctID", () => {
  1500. return Object.keys(this.value.get());
  1501. });
  1502. __publicField(this, "add", ({ id, name }) => {
  1503. if (this.has(id)) {
  1504. return;
  1505. }
  1506. this.value.set(__spreadProps(__spreadValues({}, this.value.get()), {
  1507. [id]: {
  1508. name: name.trim(),
  1509. blockedAt: Date.now()
  1510. }
  1511. }));
  1512. });
  1513. __publicField(this, "remove", (id) => {
  1514. if (!this.has(id)) {
  1515. return;
  1516. }
  1517. this.value.set(
  1518. Object.fromEntries(
  1519. Object.entries(this.value.get()).filter(([k]) => k !== id)
  1520. )
  1521. );
  1522. });
  1523. __publicField(this, "toggle", (user, force) => {
  1524. const want = force != null ? force : !this.has(user.id);
  1525. if (want) {
  1526. this.add(user);
  1527. } else {
  1528. this.remove(user.id);
  1529. }
  1530. });
  1531. }
  1532. }();
  1533.  
  1534. // src/bilibili.com/models/homePageSettings.ts
  1535. var homePageSettings_default = new class HomePageSettings {
  1536. constructor() {
  1537. __publicField(this, "value", new GMValue("homePageSettings@cb2f3e6c-a1e5-44de-b618-7715559b02ad", () => ({})));
  1538. __publicField(this, "floorCard", new class {
  1539. constructor(parent) {
  1540. this.parent = parent;
  1541. __publicField(this, "shouldExclude", (i) => {
  1542. if (this.excludeAll) {
  1543. return true;
  1544. }
  1545. if (this.excludeByChannel.includes(i.channel)) {
  1546. return true;
  1547. }
  1548. return false;
  1549. });
  1550. }
  1551. get value() {
  1552. return this.parent.value.get().floorCard;
  1553. }
  1554. set value(v) {
  1555. this.parent.value.set(__spreadProps(__spreadValues({}, this.parent.value.get()), {
  1556. floorCard: v
  1557. }));
  1558. }
  1559. get excludeAll() {
  1560. var _a2;
  1561. return (_a2 = this.value) == null ? void 0 : _a2.excludeAll;
  1562. }
  1563. set excludeAll(v) {
  1564. this.value = __spreadProps(__spreadValues({}, this.value), {
  1565. excludeAll: v
  1566. });
  1567. }
  1568. get excludeByChannel() {
  1569. var _a2, _b2;
  1570. return (_b2 = (_a2 = this.value) == null ? void 0 : _a2.excludeByChannel) != null ? _b2 : [];
  1571. }
  1572. set excludeByChannel(v) {
  1573. this.value = __spreadProps(__spreadValues({}, this.value), {
  1574. excludeByChannel: Array.from(new Set(v)).sort()
  1575. });
  1576. }
  1577. }(this));
  1578. }
  1579. get allowAdblockTips() {
  1580. var _a2;
  1581. return (_a2 = this.value.get().allowAdblockTips) != null ? _a2 : false;
  1582. }
  1583. set allowAdblockTips(v) {
  1584. this.value.set(__spreadProps(__spreadValues({}, this.value.get()), {
  1585. allowAdblockTips: v || void 0
  1586. }));
  1587. }
  1588. }();
  1589.  
  1590. // src/utils/roundDecimal.ts
  1591. function roundDecimal(v, decimalPlaces) {
  1592. const factor = __pow(10, decimalPlaces);
  1593. return Math.round(v * factor + Number.EPSILON) / factor;
  1594. }
  1595.  
  1596. // src/utils/Duration.ts
  1597. function leadingInt(s) {
  1598. let i = 0;
  1599. let x = 0;
  1600. for (; i < s.length; i += 1) {
  1601. const c = s[i];
  1602. if (c < "0" || c > "9") {
  1603. break;
  1604. }
  1605. if (x > Number.MAX_SAFE_INTEGER / 10) {
  1606. throw new Error("overflow");
  1607. }
  1608. x = x * 10 + Number.parseInt(c, 10);
  1609. if (x < 0) {
  1610. throw new Error("overflow");
  1611. }
  1612. }
  1613. return [x, s.slice(i)];
  1614. }
  1615. function leadingNegative(s) {
  1616. if (s === "") {
  1617. return [false, s];
  1618. }
  1619. const c = s[0];
  1620. if (c === "-" || c === "+") {
  1621. return [c === "-", s.slice(1)];
  1622. }
  1623. return [false, s];
  1624. }
  1625. function leadingFraction(s) {
  1626. let x = 0;
  1627. let i = 0;
  1628. let scale = 1;
  1629. let overflow = false;
  1630. for (; i < s.length; i += 1) {
  1631. const c = s[i];
  1632. if (c < "0" || c > "9") {
  1633. break;
  1634. }
  1635. if (overflow) {
  1636. continue;
  1637. }
  1638. if (x > Number.MAX_SAFE_INTEGER / 10) {
  1639. overflow = true;
  1640. continue;
  1641. }
  1642. const y = x * 10 + Number.parseInt(c, 10);
  1643. if (y < 0) {
  1644. overflow = true;
  1645. continue;
  1646. }
  1647. x = y;
  1648. scale *= 10;
  1649. }
  1650. return [x, scale, s.slice(i)];
  1651. }
  1652. function padLeft(v, c, n) {
  1653. let ret = v;
  1654. while (ret.length < n) {
  1655. ret = c + ret;
  1656. }
  1657. return ret;
  1658. }
  1659. function formatSeconds(v) {
  1660. let ret = v.toFixed(3);
  1661. if (ret.indexOf(".") < 2) {
  1662. ret = `0${ret}`;
  1663. }
  1664. return ret;
  1665. }
  1666. var _Duration = class _Duration {
  1667. constructor({
  1668. invalid = false,
  1669. negative = false,
  1670. years = 0,
  1671. months = 0,
  1672. weeks = 0,
  1673. days = 0,
  1674. hours = 0,
  1675. minutes = 0,
  1676. seconds = 0,
  1677. milliseconds = 0
  1678. } = {}) {
  1679. __publicField(this, "invalid", false);
  1680. __publicField(this, "negative", false);
  1681. __publicField(this, "years", 0);
  1682. __publicField(this, "months", 0);
  1683. __publicField(this, "weeks", 0);
  1684. __publicField(this, "days", 0);
  1685. __publicField(this, "hours", 0);
  1686. __publicField(this, "minutes", 0);
  1687. __publicField(this, "seconds", 0);
  1688. __publicField(this, "milliseconds", 0);
  1689. __publicField(this, "toISOString", () => {
  1690. if (this.invalid) {
  1691. return "";
  1692. }
  1693. let b = "";
  1694. if (this.negative) {
  1695. b += "-";
  1696. }
  1697. b += "P";
  1698. const prefixWidth = b.length;
  1699. if (this.years) {
  1700. b = this.years.toString();
  1701. b += "Y";
  1702. }
  1703. if (this.months) {
  1704. b = this.months.toString();
  1705. b += "M";
  1706. }
  1707. if (this.weeks) {
  1708. b = this.weeks.toString();
  1709. b += "W";
  1710. }
  1711. if (this.days) {
  1712. b += this.days.toString();
  1713. b += "D";
  1714. }
  1715. if (this.hours || this.minutes || this.seconds || this.milliseconds) {
  1716. b += "T";
  1717. }
  1718. if (this.hours) {
  1719. b += this.hours.toString();
  1720. b += "H";
  1721. }
  1722. if (this.minutes) {
  1723. b += this.minutes.toString();
  1724. b += "M";
  1725. }
  1726. if (this.seconds || this.milliseconds) {
  1727. b += roundDecimal(
  1728. this.seconds + this.milliseconds / _Duration.SECOND,
  1729. 3
  1730. ).toString();
  1731. b += "S";
  1732. }
  1733. if (b.length === prefixWidth) {
  1734. b += "0D";
  1735. }
  1736. return b;
  1737. });
  1738. __publicField(this, "toMilliseconds", () => {
  1739. if (this.invalid) {
  1740. return NaN;
  1741. }
  1742. return (this.negative ? -1 : 1) * (this.years * _Duration.YEAR + this.months * _Duration.MONTH + this.weeks * _Duration.WEEK + this.days * _Duration.DAY + this.hours * _Duration.HOUR + this.minutes * _Duration.MINUTE + this.seconds * _Duration.SECOND + this.milliseconds * _Duration.MILLISECOND);
  1743. });
  1744. __publicField(this, "toHours", () => {
  1745. return this.toMilliseconds() / _Duration.HOUR;
  1746. });
  1747. __publicField(this, "toString", () => {
  1748. if (this.invalid) {
  1749. return "Invalid Duration";
  1750. }
  1751. return this.toISOString();
  1752. });
  1753. /**
  1754. * Format duration to `HH:MM:SS.sss` format
  1755. */
  1756. __publicField(this, "toTimeCode", (fixed = false) => {
  1757. if (this.invalid) {
  1758. return "";
  1759. }
  1760. let v = this.toMilliseconds();
  1761. let sign = "";
  1762. if (v < 0) {
  1763. sign = "-";
  1764. v = -v;
  1765. }
  1766. v /= 1e3;
  1767. const seconds = v % 60;
  1768. v = Math.trunc(v / 60);
  1769. const minutes = v % 60;
  1770. v = Math.trunc(v / 60);
  1771. const hours = v;
  1772. let ret = `${padLeft(hours.toFixed(0), "0", 2)}:${padLeft(
  1773. minutes.toFixed(0),
  1774. "0",
  1775. 2
  1776. )}:${formatSeconds(seconds)}`;
  1777. if (!fixed) {
  1778. if (ret.startsWith("0") && ret[1] !== ":") {
  1779. ret = ret.slice(1);
  1780. }
  1781. ret = ret.replace(/\.?0+$/, "");
  1782. }
  1783. ret = sign + ret;
  1784. return ret;
  1785. });
  1786. __publicField(this, "add", (other) => {
  1787. return _Duration.fromMilliseconds(
  1788. this.toMilliseconds() + _Duration.cast(other).toMilliseconds()
  1789. );
  1790. });
  1791. __publicField(this, "sub", (other) => {
  1792. return _Duration.fromMilliseconds(
  1793. this.toMilliseconds() - _Duration.cast(other).toMilliseconds()
  1794. );
  1795. });
  1796. __publicField(this, "abs", () => {
  1797. return _Duration.fromMilliseconds(Math.abs(this.toMilliseconds()));
  1798. });
  1799. __publicField(this, "isZero", () => {
  1800. return this.toMilliseconds() === 0;
  1801. });
  1802. __publicField(this, "truncate", (unitMs) => {
  1803. if (unitMs <= 0) {
  1804. return this;
  1805. }
  1806. const ms = this.toMilliseconds();
  1807. return _Duration.fromMilliseconds(ms - ms % unitMs);
  1808. });
  1809. let invalidCount = 0;
  1810. if (invalid) {
  1811. invalidCount += 1;
  1812. }
  1813. function checkNumber(v) {
  1814. if (Number.isFinite(v)) {
  1815. return v;
  1816. }
  1817. invalidCount += 1;
  1818. return 0;
  1819. }
  1820. this.negative = negative;
  1821. this.years = checkNumber(years);
  1822. this.months = checkNumber(months);
  1823. this.weeks = checkNumber(weeks);
  1824. this.days = checkNumber(days);
  1825. this.hours = checkNumber(hours);
  1826. this.minutes = checkNumber(minutes);
  1827. this.seconds = checkNumber(seconds);
  1828. this.milliseconds = checkNumber(milliseconds);
  1829. this.invalid = invalidCount > 0;
  1830. }
  1831. get valid() {
  1832. return !this.invalid;
  1833. }
  1834. };
  1835. __publicField(_Duration, "MILLISECOND", 1);
  1836. __publicField(_Duration, "SECOND", 1e3);
  1837. __publicField(_Duration, "MINUTE", _Duration.SECOND * 60);
  1838. __publicField(_Duration, "HOUR", _Duration.MINUTE * 60);
  1839. __publicField(_Duration, "DAY", _Duration.HOUR * 24);
  1840. __publicField(_Duration, "WEEK", _Duration.DAY * 7);
  1841. __publicField(_Duration, "MONTH", _Duration.DAY / 10 * 146097 / 4800 * 10);
  1842. __publicField(_Duration, "YEAR", _Duration.MONTH * 12);
  1843. __publicField(_Duration, "fromMilliseconds", (milliseconds = 0) => {
  1844. const d2 = {};
  1845. let ms = milliseconds;
  1846. if (ms < 0) {
  1847. d2.negative = true;
  1848. ms = -ms;
  1849. }
  1850. d2.hours = Math.trunc(ms / _Duration.HOUR);
  1851. ms %= _Duration.HOUR;
  1852. d2.minutes = Math.trunc(ms / _Duration.MINUTE);
  1853. ms %= _Duration.MINUTE;
  1854. d2.seconds = Math.trunc(ms / _Duration.SECOND);
  1855. ms %= _Duration.SECOND;
  1856. d2.milliseconds = ms;
  1857. return new _Duration(d2);
  1858. });
  1859. __publicField(_Duration, "fromTimeCode", (value) => {
  1860. if (value === "") {
  1861. return new _Duration({ invalid: true });
  1862. }
  1863. let s = value;
  1864. const d2 = {
  1865. negative: false,
  1866. hours: 0,
  1867. minutes: 0,
  1868. seconds: 0
  1869. };
  1870. if (s.startsWith("-")) {
  1871. s = s.slice(1);
  1872. d2.negative = true;
  1873. }
  1874. const parts = s.split(/[::]/);
  1875. parts.splice(0, 0, ...["0", "0"].splice(parts.length - 1));
  1876. const [hours, minutes, seconds] = parts;
  1877. if (hours) {
  1878. d2.hours = parseFloat(hours);
  1879. }
  1880. if (minutes) {
  1881. d2.minutes = parseFloat(minutes);
  1882. }
  1883. if (seconds) {
  1884. d2.seconds = parseFloat(seconds);
  1885. }
  1886. return new _Duration(d2);
  1887. });
  1888. /**
  1889. * @param value iso 8601 duration string
  1890. */
  1891. __publicField(_Duration, "parse", (value) => {
  1892. const d2 = {
  1893. invalid: false,
  1894. negative: false,
  1895. years: 0,
  1896. months: 0,
  1897. weeks: 0,
  1898. days: 0,
  1899. hours: 0,
  1900. minutes: 0,
  1901. seconds: 0,
  1902. milliseconds: 0
  1903. };
  1904. let s = value;
  1905. [d2.negative, s] = leadingNegative(s);
  1906. if (s === "" || !s.startsWith("P")) {
  1907. d2.invalid = true;
  1908. return new _Duration(d2);
  1909. }
  1910. s = s.slice(1);
  1911. let afterT = false;
  1912. while (s) {
  1913. if (s.startsWith("T")) {
  1914. s = s.slice(1);
  1915. afterT = true;
  1916. }
  1917. let v = 0;
  1918. let f = 0;
  1919. let scale = 1;
  1920. let neg = false;
  1921. let pre = false;
  1922. let post = false;
  1923. [neg, s] = leadingNegative(s);
  1924. const pl = s.length;
  1925. [v, s] = leadingInt(s);
  1926. pre = pl !== s.length;
  1927. if (neg) {
  1928. v = -v;
  1929. }
  1930. if (s.startsWith(".")) {
  1931. s = s.slice(1);
  1932. const pl2 = s.length;
  1933. [f, scale, s] = leadingFraction(s);
  1934. post = pl2 !== s.length;
  1935. if (neg) {
  1936. f = -f;
  1937. }
  1938. }
  1939. if (!pre && !post) {
  1940. d2.invalid = true;
  1941. return new _Duration(d2);
  1942. }
  1943. const u = s[0];
  1944. s = s.slice(1);
  1945. if (!afterT) {
  1946. switch (u) {
  1947. case "Y":
  1948. d2.years += v;
  1949. d2.months += f * (_Duration.YEAR / _Duration.MONTH / scale);
  1950. break;
  1951. case "M":
  1952. d2.months += v;
  1953. d2.weeks += f * (_Duration.MONTH / _Duration.WEEK / scale);
  1954. break;
  1955. case "W":
  1956. d2.weeks += v;
  1957. d2.days += f * (_Duration.WEEK / _Duration.DAY / scale);
  1958. break;
  1959. case "D":
  1960. d2.days += v;
  1961. d2.hours += f * (_Duration.DAY / _Duration.HOUR / scale);
  1962. break;
  1963. default:
  1964. d2.invalid = false;
  1965. return new _Duration(d2);
  1966. }
  1967. } else {
  1968. switch (u) {
  1969. case "H":
  1970. d2.hours += v;
  1971. d2.minutes += f * (_Duration.HOUR / _Duration.MINUTE / scale);
  1972. break;
  1973. case "M":
  1974. d2.minutes += v;
  1975. d2.seconds += f * (_Duration.MINUTE / _Duration.SECOND / scale);
  1976. break;
  1977. case "S":
  1978. d2.seconds += v;
  1979. d2.milliseconds += f * (_Duration.SECOND / _Duration.MILLISECOND / scale);
  1980. break;
  1981. default:
  1982. d2.invalid = true;
  1983. return new _Duration(d2);
  1984. }
  1985. }
  1986. if (post && s !== "") {
  1987. d2.invalid = true;
  1988. return new _Duration(d2);
  1989. }
  1990. }
  1991. return new _Duration(d2);
  1992. });
  1993. __publicField(_Duration, "cast", (v) => {
  1994. if (v instanceof _Duration) {
  1995. return v;
  1996. }
  1997. if (typeof v === "string") {
  1998. if (v.startsWith("P") || v.startsWith("-P")) {
  1999. return _Duration.parse(v);
  2000. }
  2001. return _Duration.fromTimeCode(v);
  2002. }
  2003. return new _Duration(v);
  2004. });
  2005. var Duration = _Duration;
  2006.  
  2007. // src/utils/optionalArray.ts
  2008. function optionalArray(arr) {
  2009. if (!arr || arr.length === 0) {
  2010. return;
  2011. }
  2012. return arr;
  2013. }
  2014.  
  2015. // src/bilibili.com/models/videoListSettings.ts
  2016. var videoListSettings_default = new class VideoListSettings {
  2017. constructor() {
  2018. __publicField(this, "value", new GMValue("videoListSettings@4eb93ea9-8748-4647-876f-30451395e561", () => ({})));
  2019. }
  2020. get allowAdvertisement() {
  2021. var _a2;
  2022. return (_a2 = this.value.get().allowAdvertisement) != null ? _a2 : false;
  2023. }
  2024. set allowAdvertisement(v) {
  2025. this.value.set(__spreadProps(__spreadValues({}, this.value.get()), {
  2026. allowAdvertisement: v || void 0
  2027. }));
  2028. }
  2029. get excludeKeywords() {
  2030. var _a2;
  2031. return (_a2 = this.value.get().excludeKeywords) != null ? _a2 : [];
  2032. }
  2033. set excludeKeywords(v) {
  2034. this.value.set(__spreadProps(__spreadValues({}, this.value.get()), {
  2035. excludeKeywords: optionalArray(v.filter((i) => i))
  2036. }));
  2037. }
  2038. get durationGte() {
  2039. var _a2;
  2040. return Duration.parse((_a2 = this.value.get().durationGte) != null ? _a2 : "");
  2041. }
  2042. set durationGte(v) {
  2043. const d2 = Duration.cast(v);
  2044. if (d2.toMilliseconds() >= Duration.HOUR) {
  2045. this.durationGte = "PT1M";
  2046. return;
  2047. }
  2048. this.value.set(__spreadProps(__spreadValues({}, this.value.get()), {
  2049. durationGte: d2.invalid ? void 0 : d2.toISOString()
  2050. }));
  2051. }
  2052. get durationLt() {
  2053. var _a2;
  2054. const v = Duration.parse((_a2 = this.value.get().durationLt) != null ? _a2 : "");
  2055. if (v.toMilliseconds() <= 10 * Duration.MINUTE) {
  2056. return Duration.parse("");
  2057. }
  2058. return v;
  2059. }
  2060. set durationLt(v) {
  2061. const d2 = Duration.cast(v);
  2062. if (d2.valid && d2.toMilliseconds() <= 10 * Duration.MINUTE) {
  2063. this.durationLt = "PT30M";
  2064. return;
  2065. }
  2066. this.value.set(__spreadProps(__spreadValues({}, this.value.get()), {
  2067. durationLt: d2.invalid ? void 0 : d2.toISOString()
  2068. }));
  2069. }
  2070. }();
  2071.  
  2072. // src/bilibili.com/models/searchSettings.ts
  2073. var searchSettings_default = new class SearchSettings {
  2074. constructor() {
  2075. __publicField(this, "value", new GMValue("searchSettings@aa1595c8-1664-40de-a80c-9de375c2466a", () => ({})));
  2076. }
  2077. get strictTitleMatch() {
  2078. var _a2;
  2079. return (_a2 = this.value.get().strictTitleMatch) != null ? _a2 : false;
  2080. }
  2081. set strictTitleMatch(v) {
  2082. this.value.set(__spreadProps(__spreadValues({}, this.value.get()), {
  2083. strictTitleMatch: v || void 0
  2084. }));
  2085. }
  2086. get navSuggestion() {
  2087. var _a2;
  2088. return (_a2 = this.value.get().navSuggestion) != null ? _a2 : "on";
  2089. }
  2090. set navSuggestion(v) {
  2091. this.value.set(__spreadProps(__spreadValues({}, this.value.get()), {
  2092. navSuggestion: v === "on" ? void 0 : v
  2093. }));
  2094. }
  2095. get trending() {
  2096. var _a2;
  2097. return (_a2 = this.value.get().trending) != null ? _a2 : "on";
  2098. }
  2099. set trending(v) {
  2100. this.value.set(__spreadProps(__spreadValues({}, this.value.get()), {
  2101. trending: v === "on" ? void 0 : v
  2102. }));
  2103. }
  2104. }();
  2105.  
  2106. // src/bilibili.com/models/blockedLiveRooms.ts
  2107. var blockedLiveRooms_default = new class {
  2108. constructor() {
  2109. __publicField(this, "value", new GMValue(
  2110. "blockedLiveRooms@031f022e-51b9-4361-8cfb-80263a0d7595",
  2111. () => ({})
  2112. ));
  2113. __publicField(this, "has", (id) => {
  2114. return !!this.value.get()[id];
  2115. });
  2116. __publicField(this, "get", (id) => {
  2117. const value = this.value.get()[id];
  2118. return {
  2119. id,
  2120. blockedAt: new Date(value.blockedAt),
  2121. owner: value.owner
  2122. };
  2123. });
  2124. __publicField(this, "distinctID", () => {
  2125. return Object.keys(this.value.get());
  2126. });
  2127. __publicField(this, "add", ({ id, owner }) => {
  2128. if (this.has(id)) {
  2129. return;
  2130. }
  2131. this.value.set(__spreadProps(__spreadValues({}, this.value.get()), {
  2132. [id]: {
  2133. owner: owner.trim(),
  2134. blockedAt: Date.now()
  2135. }
  2136. }));
  2137. });
  2138. __publicField(this, "remove", (id) => {
  2139. if (!this.has(id)) {
  2140. return;
  2141. }
  2142. this.value.set(
  2143. Object.fromEntries(
  2144. Object.entries(this.value.get()).filter(([k]) => k !== id)
  2145. )
  2146. );
  2147. });
  2148. __publicField(this, "toggle", (room, force) => {
  2149. const want = force != null ? force : !this.has(room.id);
  2150. if (want) {
  2151. this.add(room);
  2152. } else {
  2153. this.remove(room.id);
  2154. }
  2155. });
  2156. }
  2157. }();
  2158.  
  2159. // src/utils/obtainHTMLElementByDataKey.ts
  2160. function obtainHTMLElementByDataKey({
  2161. tag: tag2,
  2162. key: key2,
  2163. parentNode = document,
  2164. onDidCreate
  2165. }) {
  2166. const match = parentNode.querySelector(
  2167. `[data-${key2}]`
  2168. );
  2169. if (match) {
  2170. return match;
  2171. }
  2172. const el = document.createElement(tag2);
  2173. el.setAttribute(`data-${key2}`, "");
  2174. onDidCreate == null ? void 0 : onDidCreate(el);
  2175. return el;
  2176. }
  2177.  
  2178. // src/bilibili.com/style.css
  2179. var style_default = '/* \n用户脚本样式\nhttps://github.com/NateScarlet/user-scripts/blob/master/src/bilibili.com/\n*/\n\n/* \n! tailwindcss v3.3.2 | MIT License | https://tailwindcss.com\n*/\n\n/*\n1. Prevent padding and border from affecting element width. (https://github.com/mozdevs/cssremedy/issues/4)\n2. Allow adding a border to an element by just adding a border-width. (https://github.com/tailwindcss/tailwindcss/pull/116)\n*/\n\n*,\n::before,\n::after {\n box-sizing: border-box; /* 1 */\n border-width: 0; /* 2 */\n border-style: solid; /* 2 */\n border-color: #e5e7eb; /* 2 */\n}\n\n::before,\n::after {\n --tw-content: \'\';\n}\n\n/*\n1. Use a consistent sensible line-height in all browsers.\n2. Prevent adjustments of font size after orientation changes in iOS.\n3. Use a more readable tab size.\n4. Use the user\'s configured `sans` font-family by default.\n5. Use the user\'s configured `sans` font-feature-settings by default.\n6. Use the user\'s configured `sans` font-variation-settings by default.\n*/\n\nhtml {\n line-height: 1.5; /* 1 */\n -webkit-text-size-adjust: 100%; /* 2 */\n -moz-tab-size: 4; /* 3 */\n -o-tab-size: 4;\n tab-size: 4; /* 3 */\n font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; /* 4 */\n font-feature-settings: normal; /* 5 */\n font-variation-settings: normal; /* 6 */\n}\n\n/*\n1. Remove the margin in all browsers.\n2. Inherit line-height from `html` so users can set them as a class directly on the `html` element.\n*/\n\nbody {\n margin: 0; /* 1 */\n line-height: inherit; /* 2 */\n}\n\n/*\n1. Add the correct height in Firefox.\n2. Correct the inheritance of border color in Firefox. (https://bugzilla.mozilla.org/show_bug.cgi?id=190655)\n3. Ensure horizontal rules are visible by default.\n*/\n\nhr {\n height: 0; /* 1 */\n color: inherit; /* 2 */\n border-top-width: 1px; /* 3 */\n}\n\n/*\nAdd the correct text decoration in Chrome, Edge, and Safari.\n*/\n\nabbr:where([title]) {\n -webkit-text-decoration: underline dotted;\n text-decoration: underline dotted;\n}\n\n/*\nRemove the default font size and weight for headings.\n*/\n\nh1,\nh2,\nh3,\nh4,\nh5,\nh6 {\n font-size: inherit;\n font-weight: inherit;\n}\n\n/*\nReset links to optimize for opt-in styling instead of opt-out.\n*/\n\na {\n color: inherit;\n text-decoration: inherit;\n}\n\n/*\nAdd the correct font weight in Edge and Safari.\n*/\n\nb,\nstrong {\n font-weight: bolder;\n}\n\n/*\n1. Use the user\'s configured `mono` font family by default.\n2. Correct the odd `em` font sizing in all browsers.\n*/\n\ncode,\nkbd,\nsamp,\npre {\n font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; /* 1 */\n font-size: 1em; /* 2 */\n}\n\n/*\nAdd the correct font size in all browsers.\n*/\n\nsmall {\n font-size: 80%;\n}\n\n/*\nPrevent `sub` and `sup` elements from affecting the line height in all browsers.\n*/\n\nsub,\nsup {\n font-size: 75%;\n line-height: 0;\n position: relative;\n vertical-align: baseline;\n}\n\nsub {\n bottom: -0.25em;\n}\n\nsup {\n top: -0.5em;\n}\n\n/*\n1. Remove text indentation from table contents in Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=999088, https://bugs.webkit.org/show_bug.cgi?id=201297)\n2. Correct table border color inheritance in all Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=935729, https://bugs.webkit.org/show_bug.cgi?id=195016)\n3. Remove gaps between table borders by default.\n*/\n\ntable {\n text-indent: 0; /* 1 */\n border-color: inherit; /* 2 */\n border-collapse: collapse; /* 3 */\n}\n\n/*\n1. Change the font styles in all browsers.\n2. Remove the margin in Firefox and Safari.\n3. Remove default padding in all browsers.\n*/\n\nbutton,\ninput,\noptgroup,\nselect,\ntextarea {\n font-family: inherit; /* 1 */\n font-size: 100%; /* 1 */\n font-weight: inherit; /* 1 */\n line-height: inherit; /* 1 */\n color: inherit; /* 1 */\n margin: 0; /* 2 */\n padding: 0; /* 3 */\n}\n\n/*\nRemove the inheritance of text transform in Edge and Firefox.\n*/\n\nbutton,\nselect {\n text-transform: none;\n}\n\n/*\n1. Correct the inability to style clickable types in iOS and Safari.\n2. Remove default button styles.\n*/\n\nbutton,\n[type=\'button\'],\n[type=\'reset\'],\n[type=\'submit\'] {\n -webkit-appearance: button; /* 1 */\n background-color: transparent; /* 2 */\n background-image: none; /* 2 */\n}\n\n/*\nUse the modern Firefox focus style for all focusable elements.\n*/\n\n:-moz-focusring {\n outline: auto;\n}\n\n/*\nRemove the additional `:invalid` styles in Firefox. (https://github.com/mozilla/gecko-dev/blob/2f9eacd9d3d995c937b4251a5557d95d494c9be1/layout/style/res/forms.css#L728-L737)\n*/\n\n:-moz-ui-invalid {\n box-shadow: none;\n}\n\n/*\nAdd the correct vertical alignment in Chrome and Firefox.\n*/\n\nprogress {\n vertical-align: baseline;\n}\n\n/*\nCorrect the cursor style of increment and decrement buttons in Safari.\n*/\n\n::-webkit-inner-spin-button,\n::-webkit-outer-spin-button {\n height: auto;\n}\n\n/*\n1. Correct the odd appearance in Chrome and Safari.\n2. Correct the outline style in Safari.\n*/\n\n[type=\'search\'] {\n -webkit-appearance: textfield; /* 1 */\n outline-offset: -2px; /* 2 */\n}\n\n/*\nRemove the inner padding in Chrome and Safari on macOS.\n*/\n\n::-webkit-search-decoration {\n -webkit-appearance: none;\n}\n\n/*\n1. Correct the inability to style clickable types in iOS and Safari.\n2. Change font properties to `inherit` in Safari.\n*/\n\n::-webkit-file-upload-button {\n -webkit-appearance: button; /* 1 */\n font: inherit; /* 2 */\n}\n\n/*\nAdd the correct display in Chrome and Safari.\n*/\n\nsummary {\n display: list-item;\n}\n\n/*\nRemoves the default spacing and border for appropriate elements.\n*/\n\nblockquote,\ndl,\ndd,\nh1,\nh2,\nh3,\nh4,\nh5,\nh6,\nhr,\nfigure,\np,\npre {\n margin: 0;\n}\n\nfieldset {\n margin: 0;\n padding: 0;\n}\n\nlegend {\n padding: 0;\n}\n\nol,\nul,\nmenu {\n list-style: none;\n margin: 0;\n padding: 0;\n}\n\n/*\nPrevent resizing textareas horizontally by default.\n*/\n\ntextarea {\n resize: vertical;\n}\n\n/*\n1. Reset the default placeholder opacity in Firefox. (https://github.com/tailwindlabs/tailwindcss/issues/3300)\n2. Set the default placeholder color to the user\'s configured gray 400 color.\n*/\n\ninput::-moz-placeholder, textarea::-moz-placeholder {\n opacity: 1; /* 1 */\n color: #9ca3af; /* 2 */\n}\n\ninput::placeholder,\ntextarea::placeholder {\n opacity: 1; /* 1 */\n color: #9ca3af; /* 2 */\n}\n\n/*\nSet the default cursor for buttons.\n*/\n\nbutton,\n[role="button"] {\n cursor: pointer;\n}\n\n/*\nMake sure disabled buttons don\'t get the pointer cursor.\n*/\n\n:disabled {\n cursor: default;\n}\n\n/*\n1. Make replaced elements `display: block` by default. (https://github.com/mozdevs/cssremedy/issues/14)\n2. Add `vertical-align: middle` to align replaced elements more sensibly by default. (https://github.com/jensimmons/cssremedy/issues/14#issuecomment-634934210)\n This can trigger a poorly considered lint error in some tools but is included by design.\n*/\n\nimg,\nsvg,\nvideo,\ncanvas,\naudio,\niframe,\nembed,\nobject {\n display: block; /* 1 */\n vertical-align: middle; /* 2 */\n}\n\n/*\nConstrain images and videos to the parent width and preserve their intrinsic aspect ratio. (https://github.com/mozdevs/cssremedy/issues/14)\n*/\n\nimg,\nvideo {\n max-width: 100%;\n height: auto;\n}\n\n/* Make elements with the HTML hidden attribute stay hidden by default */\n\n[hidden] {\n display: none;\n}\n\n*, ::before, ::after {\n --tw-border-spacing-x: 0;\n --tw-border-spacing-y: 0;\n --tw-translate-x: 0;\n --tw-translate-y: 0;\n --tw-rotate: 0;\n --tw-skew-x: 0;\n --tw-skew-y: 0;\n --tw-scale-x: 1;\n --tw-scale-y: 1;\n --tw-pan-x: ;\n --tw-pan-y: ;\n --tw-pinch-zoom: ;\n --tw-scroll-snap-strictness: proximity;\n --tw-gradient-from-position: ;\n --tw-gradient-via-position: ;\n --tw-gradient-to-position: ;\n --tw-ordinal: ;\n --tw-slashed-zero: ;\n --tw-numeric-figure: ;\n --tw-numeric-spacing: ;\n --tw-numeric-fraction: ;\n --tw-ring-inset: ;\n --tw-ring-offset-width: 0px;\n --tw-ring-offset-color: #fff;\n --tw-ring-color: rgb(59 130 246 / 0.5);\n --tw-ring-offset-shadow: 0 0 #0000;\n --tw-ring-shadow: 0 0 #0000;\n --tw-shadow: 0 0 #0000;\n --tw-shadow-colored: 0 0 #0000;\n --tw-blur: ;\n --tw-brightness: ;\n --tw-contrast: ;\n --tw-grayscale: ;\n --tw-hue-rotate: ;\n --tw-invert: ;\n --tw-saturate: ;\n --tw-sepia: ;\n --tw-drop-shadow: ;\n --tw-backdrop-blur: ;\n --tw-backdrop-brightness: ;\n --tw-backdrop-contrast: ;\n --tw-backdrop-grayscale: ;\n --tw-backdrop-hue-rotate: ;\n --tw-backdrop-invert: ;\n --tw-backdrop-opacity: ;\n --tw-backdrop-saturate: ;\n --tw-backdrop-sepia: ;\n}\n\n::backdrop {\n --tw-border-spacing-x: 0;\n --tw-border-spacing-y: 0;\n --tw-translate-x: 0;\n --tw-translate-y: 0;\n --tw-rotate: 0;\n --tw-skew-x: 0;\n --tw-skew-y: 0;\n --tw-scale-x: 1;\n --tw-scale-y: 1;\n --tw-pan-x: ;\n --tw-pan-y: ;\n --tw-pinch-zoom: ;\n --tw-scroll-snap-strictness: proximity;\n --tw-gradient-from-position: ;\n --tw-gradient-via-position: ;\n --tw-gradient-to-position: ;\n --tw-ordinal: ;\n --tw-slashed-zero: ;\n --tw-numeric-figure: ;\n --tw-numeric-spacing: ;\n --tw-numeric-fraction: ;\n --tw-ring-inset: ;\n --tw-ring-offset-width: 0px;\n --tw-ring-offset-color: #fff;\n --tw-ring-color: rgb(59 130 246 / 0.5);\n --tw-ring-offset-shadow: 0 0 #0000;\n --tw-ring-shadow: 0 0 #0000;\n --tw-shadow: 0 0 #0000;\n --tw-shadow-colored: 0 0 #0000;\n --tw-blur: ;\n --tw-brightness: ;\n --tw-contrast: ;\n --tw-grayscale: ;\n --tw-hue-rotate: ;\n --tw-invert: ;\n --tw-saturate: ;\n --tw-sepia: ;\n --tw-drop-shadow: ;\n --tw-backdrop-blur: ;\n --tw-backdrop-brightness: ;\n --tw-backdrop-contrast: ;\n --tw-backdrop-grayscale: ;\n --tw-backdrop-hue-rotate: ;\n --tw-backdrop-invert: ;\n --tw-backdrop-opacity: ;\n --tw-backdrop-saturate: ;\n --tw-backdrop-sepia: ;\n}\n\n* {\n font-size: 16px;\n line-height: 24px;\n}\n\n.static {\n position: static;\n}\n\n.fixed {\n position: fixed;\n}\n\n.absolute {\n position: absolute;\n}\n\n.relative {\n position: relative;\n}\n\n.sticky {\n position: sticky;\n}\n\n.inset-0 {\n inset: 0px;\n}\n\n.inset-y-0 {\n top: 0px;\n bottom: 0px;\n}\n\n.left-2 {\n left: 0.5rem;\n}\n\n.right-0 {\n right: 0px;\n}\n\n.top-0 {\n top: 0px;\n}\n\n.top-2 {\n top: 0.5rem;\n}\n\n.isolate {\n isolation: isolate;\n}\n\n.z-20 {\n z-index: 20;\n}\n\n.m-1 {\n margin: 0.25rem;\n}\n\n.my-1 {\n margin-top: 0.25rem;\n margin-bottom: 0.25rem;\n}\n\n.inline {\n display: inline;\n}\n\n.flex {\n display: flex;\n}\n\n.inline-flex {\n display: inline-flex;\n}\n\n.table {\n display: table;\n}\n\n.\\!hidden {\n display: none !important;\n}\n\n.hidden {\n display: none;\n}\n\n.h-7 {\n height: 1.75rem;\n}\n\n.h-8 {\n height: 2rem;\n}\n\n.h-\\[1\\.25em\\] {\n height: 1.25em;\n}\n\n.max-h-\\[50vh\\] {\n max-height: 50vh;\n}\n\n.w-32 {\n width: 8rem;\n}\n\n.w-full {\n width: 100%;\n}\n\n.w-screen {\n width: 100vw;\n}\n\n.max-w-4xl {\n max-width: 56rem;\n}\n\n.flex-1 {\n flex: 1 1 0%;\n}\n\n.flex-auto {\n flex: 1 1 auto;\n}\n\n.flex-none {\n flex: none;\n}\n\n.table-fixed {\n table-layout: fixed;\n}\n\n.border-separate {\n border-collapse: separate;\n}\n\n.border-spacing-2 {\n --tw-border-spacing-x: 0.5rem;\n --tw-border-spacing-y: 0.5rem;\n border-spacing: var(--tw-border-spacing-x) var(--tw-border-spacing-y);\n}\n\n.translate-x-full {\n --tw-translate-x: 100%;\n transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));\n}\n\n.cursor-pointer {\n cursor: pointer;\n}\n\n.cursor-zoom-out {\n cursor: zoom-out;\n}\n\n.flex-col {\n flex-direction: column;\n}\n\n.flex-wrap {\n flex-wrap: wrap;\n}\n\n.items-center {\n align-items: center;\n}\n\n.gap-2 {\n gap: 0.5rem;\n}\n\n.space-x-2 > :not([hidden]) ~ :not([hidden]) {\n --tw-space-x-reverse: 0;\n margin-right: calc(0.5rem * var(--tw-space-x-reverse));\n margin-left: calc(0.5rem * calc(1 - var(--tw-space-x-reverse)));\n}\n\n.space-y-1 > :not([hidden]) ~ :not([hidden]) {\n --tw-space-y-reverse: 0;\n margin-top: calc(0.25rem * calc(1 - var(--tw-space-y-reverse)));\n margin-bottom: calc(0.25rem * var(--tw-space-y-reverse));\n}\n\n.self-end {\n align-self: flex-end;\n}\n\n.overflow-auto {\n overflow: auto;\n}\n\n.overflow-hidden {\n overflow: hidden;\n}\n\n.rounded {\n border-radius: 0.25rem;\n}\n\n.rounded-md {\n border-radius: 0.375rem;\n}\n\n.border {\n border-width: 1px;\n}\n\n.border-none {\n border-style: none;\n}\n\n.bg-\\[rgba\\(33\\2c 33\\2c 33\\2c \\.8\\)\\] {\n background-color: rgba(33,33,33,.8);\n}\n\n.bg-gray-200 {\n --tw-bg-opacity: 1;\n background-color: rgb(229 231 235 / var(--tw-bg-opacity));\n}\n\n.bg-gray-300 {\n --tw-bg-opacity: 1;\n background-color: rgb(209 213 219 / var(--tw-bg-opacity));\n}\n\n.bg-white {\n --tw-bg-opacity: 1;\n background-color: rgb(255 255 255 / var(--tw-bg-opacity));\n}\n\n.bg-opacity-25 {\n --tw-bg-opacity: 0.25;\n}\n\n.fill-current {\n fill: currentColor;\n}\n\n.p-1 {\n padding: 0.25rem;\n}\n\n.p-2 {\n padding: 0.5rem;\n}\n\n.px-1 {\n padding-left: 0.25rem;\n padding-right: 0.25rem;\n}\n\n.px-2 {\n padding-left: 0.5rem;\n padding-right: 0.5rem;\n}\n\n.py-1 {\n padding-top: 0.25rem;\n padding-bottom: 0.25rem;\n}\n\n.text-center {\n text-align: center;\n}\n\n.text-right {\n text-align: right;\n}\n\n.align-top {\n vertical-align: top;\n}\n\n.text-sm {\n font-size: 14px;\n line-height: 20px;\n}\n\n.text-black {\n --tw-text-opacity: 1;\n color: rgb(0 0 0 / var(--tw-text-opacity));\n}\n\n.text-blue-500 {\n --tw-text-opacity: 1;\n color: rgb(59 130 246 / var(--tw-text-opacity));\n}\n\n.text-gray-500 {\n --tw-text-opacity: 1;\n color: rgb(107 114 128 / var(--tw-text-opacity));\n}\n\n.text-white {\n --tw-text-opacity: 1;\n color: rgb(255 255 255 / var(--tw-text-opacity));\n}\n\n.underline {\n text-decoration-line: underline;\n}\n\n.opacity-0 {\n opacity: 0;\n}\n\n.opacity-100 {\n opacity: 1;\n}\n\n.blur {\n --tw-blur: blur(8px);\n filter: var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow);\n}\n\n.filter {\n filter: var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow);\n}\n\n.backdrop-blur {\n --tw-backdrop-blur: blur(8px);\n -webkit-backdrop-filter: var(--tw-backdrop-blur) var(--tw-backdrop-brightness) var(--tw-backdrop-contrast) var(--tw-backdrop-grayscale) var(--tw-backdrop-hue-rotate) var(--tw-backdrop-invert) var(--tw-backdrop-opacity) var(--tw-backdrop-saturate) var(--tw-backdrop-sepia);\n backdrop-filter: var(--tw-backdrop-blur) var(--tw-backdrop-brightness) var(--tw-backdrop-contrast) var(--tw-backdrop-grayscale) var(--tw-backdrop-hue-rotate) var(--tw-backdrop-invert) var(--tw-backdrop-opacity) var(--tw-backdrop-saturate) var(--tw-backdrop-sepia);\n}\n\n.transition {\n transition-property: color, background-color, border-color, text-decoration-color, fill, stroke, opacity, box-shadow, transform, filter, -webkit-backdrop-filter;\n transition-property: color, background-color, border-color, text-decoration-color, fill, stroke, opacity, box-shadow, transform, filter, backdrop-filter;\n transition-property: color, background-color, border-color, text-decoration-color, fill, stroke, opacity, box-shadow, transform, filter, backdrop-filter, -webkit-backdrop-filter;\n transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);\n transition-duration: 150ms;\n}\n\n.transition-transform {\n transition-property: transform;\n transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);\n transition-duration: 150ms;\n}\n\n.duration-200 {\n transition-duration: 200ms;\n}\n\n.ease-in-out {\n transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);\n}\n\n.even\\:bg-gray-100:nth-child(even) {\n --tw-bg-opacity: 1;\n background-color: rgb(243 244 246 / var(--tw-bg-opacity));\n}\n\n.hover\\:bg-gray-200:hover {\n --tw-bg-opacity: 1;\n background-color: rgb(229 231 235 / var(--tw-bg-opacity));\n}\n\n.group:hover .group-hover\\:opacity-100 {\n opacity: 1;\n}\n\n@media (min-width: 1024px) {\n\n .lg\\:hidden {\n display: none;\n }\n}\n';
  2180.  
  2181. // src/bilibili.com/utils/obtainStyledShadowRoot.ts
  2182. var key = "36fff111-0148-4cc1-869b-06dfdfc36861";
  2183. var map = /* @__PURE__ */ new WeakMap();
  2184. function obtainStyledShadowRoot(el) {
  2185. var _a2, _b2;
  2186. const root2 = (_b2 = (_a2 = map.get(el)) != null ? _a2 : el.shadowRoot) != null ? _b2 : el.attachShadow({ mode: "closed" });
  2187. map.set(el, root2);
  2188. obtainHTMLElementByDataKey({
  2189. tag: "style",
  2190. key,
  2191. parentNode: root2,
  2192. onDidCreate: (el2) => {
  2193. el2.innerHTML = style_default;
  2194. root2.prepend(el2);
  2195. }
  2196. });
  2197. return root2;
  2198. }
  2199.  
  2200. // src/bilibili.com/components/SettingsDrawer.ts
  2201. var _SettingsDrawer = class _SettingsDrawer {
  2202. constructor() {
  2203. __publicField(this, "isOpen", false);
  2204. __publicField(this, "active", false);
  2205. __publicField(this, "open", () => {
  2206. this.active = true;
  2207. this.render();
  2208. setTimeout(() => {
  2209. this.isOpen = true;
  2210. this.render();
  2211. }, 20);
  2212. });
  2213. __publicField(this, "close", () => {
  2214. this.isOpen = false;
  2215. this.render();
  2216. });
  2217. __publicField(this, "excludedKeywordsBuffer");
  2218. __publicField(this, "onExcludeKeywordInput", (e) => {
  2219. const el = e.target;
  2220. this.excludedKeywords = el.value;
  2221. growTextAreaHeight(el);
  2222. });
  2223. __publicField(this, "onVideListDurationGteChange", debounce_default((e) => {
  2224. const el = e.target;
  2225. videoListSettings_default.durationGte = el.value;
  2226. el.value = videoListSettings_default.durationGte.toTimeCode();
  2227. }, 5e3));
  2228. __publicField(this, "onVideListDurationLtChange", debounce_default((e) => {
  2229. const el = e.target;
  2230. videoListSettings_default.durationLt = el.value;
  2231. el.value = videoListSettings_default.durationLt.toTimeCode();
  2232. }, 5e3));
  2233. __publicField(this, "render", () => {
  2234. render(
  2235. this.html(),
  2236. obtainStyledShadowRoot(
  2237. obtainHTMLElementByID({
  2238. tag: "div",
  2239. id: _SettingsDrawer.id,
  2240. onDidCreate: (el) => {
  2241. el.style.position = "fixed";
  2242. el.style.zIndex = "9999";
  2243. document.body.append(el);
  2244. }
  2245. })
  2246. )
  2247. );
  2248. });
  2249. }
  2250. html() {
  2251. if (!this.active) {
  2252. return nothing;
  2253. }
  2254. return html`
  2255. <div
  2256. class="
  2257. fixed inset-0
  2258. bg-white bg-opacity-25 backdrop-blur
  2259. cursor-zoom-out transition duration-200 ease-in-out
  2260. ${this.isOpen ? "opacity-100" : "opacity-0"}
  2261. "
  2262. @click=${() => this.close()}
  2263. >
  2264. </div>
  2265. <div
  2266. class="
  2267. fixed inset-y-0 right-0 w-screen max-w-4xl
  2268. bg-white overflow-auto p-2 space-y-1
  2269. transition-transform
  2270. ${this.isOpen ? "" : "translate-x-full"}
  2271. "
  2272. @transitionend=${() => {
  2273. if (!this.isOpen) {
  2274. this.active = false;
  2275. this.render();
  2276. }
  2277. }}
  2278. >
  2279. <button
  2280. type="button"
  2281. class="lg:hidden self-end flex items-center"
  2282. @click=${() => this.close()}
  2283. >
  2284. <svg
  2285. viewBox="0 0 24 24"
  2286. fill="none"
  2287. xmlns="http://www.w3.org/2000/svg"
  2288. class="h-[1.25em] align-top"
  2289. >
  2290. <path fill-rule="evenodd" clip-rule="evenodd" d=${mdiClose} fill="currentColor">
  2291. </svg>
  2292. <span>关闭</span>
  2293. </button>
  2294. ${this.homePageSettings()}
  2295. ${this.searchSettings()}
  2296. ${this.videoListSettings()}
  2297. ${this.userTable()}
  2298. ${this.liveRoomTable()}
  2299. </div>`;
  2300. }
  2301. homePageSettings() {
  2302. return html`
  2303. <section>
  2304. <h1 class="text-sm text-gray-500">主页</h1>
  2305. <div class="px-1">
  2306. <label>
  2307. <input
  2308. type="checkbox"
  2309. .checked="${homePageSettings_default.allowAdblockTips}"
  2310. @change="${(e) => {
  2311. const el = e.target;
  2312. homePageSettings_default.allowAdblockTips = el.checked;
  2313. }}"
  2314. />
  2315. <span>允许</span>
  2316. <span class="text-sm rounded"
  2317. style="
  2318. color: #e58900;
  2319. background-color: #fff0e3;
  2320. "
  2321. >检测到您的页面...</span>
  2322. <span>提示</span>
  2323. </label>
  2324. <section>
  2325. <h2 class="text-gray-500 text-sm">楼层推广卡片</h2>
  2326. <div class="px-1">
  2327. <div>
  2328. <label>
  2329. <input
  2330. type="checkbox"
  2331. ?checked="${homePageSettings_default.floorCard.excludeAll}"
  2332. @change="${(e) => {
  2333. const el = e.target;
  2334. homePageSettings_default.floorCard.excludeAll = el.checked;
  2335. }}"
  2336. />
  2337. <span>屏蔽所有</span>
  2338. </label>
  2339. </div>
  2340. ${(() => {
  2341. if (homePageSettings_default.floorCard.excludeAll) {
  2342. return nothing;
  2343. }
  2344. if (homePageSettings_default.floorCard.excludeByChannel.length === 0) {
  2345. return html`<div class="text-gray-500 text-sm">
  2346. 可通过指针悬停在卡片上时左上角显示的按钮来屏蔽单个频道的推广
  2347. </div>`;
  2348. }
  2349. return html`
  2350. <div>
  2351. <h2 class="flex-none text-sm text-gray-500">
  2352. 已屏蔽频道 <span class="text-sm">(${homePageSettings_default.floorCard.excludeByChannel.length})</span>
  2353. </h1>
  2354. <ol class="flex flex-wrap gap-2 items-center">
  2355. ${homePageSettings_default.floorCard.excludeByChannel.map(
  2356. (channel) => {
  2357. return html`
  2358. <li class="bg-gray-300 rounded px-1 flex items-center">
  2359. <span>${channel}</span>
  2360. <button
  2361. type="button"
  2362. @click=${() => {
  2363. homePageSettings_default.floorCard.excludeByChannel = homePageSettings_default.floorCard.excludeByChannel.filter(
  2364. (i) => i !== channel
  2365. );
  2366. }}
  2367. >
  2368. <svg
  2369. viewBox="0 0 24 24"
  2370. fill="none"
  2371. xmlns="http://www.w3.org/2000/svg"
  2372. class="h-[1.25em]"
  2373. >
  2374. <path fill-rule="evenodd" clip-rule="evenodd" d=${mdiClose} fill="currentColor">
  2375. </svg>
  2376. </button>
  2377. </li>`;
  2378. }
  2379. )}
  2380. </ol>
  2381. </div>
  2382. `;
  2383. })()}
  2384. </section>
  2385. </div>
  2386. </div>
  2387. </section>
  2388. `;
  2389. }
  2390. get excludedKeywords() {
  2391. var _a2;
  2392. return (_a2 = this.excludedKeywordsBuffer) != null ? _a2 : videoListSettings_default.excludeKeywords.join("\n");
  2393. }
  2394. set excludedKeywords(v) {
  2395. this.excludedKeywordsBuffer = v;
  2396. videoListSettings_default.excludeKeywords = v.split("\n");
  2397. }
  2398. videoListSettings() {
  2399. return html`
  2400. <section>
  2401. <h1 class="text-sm text-gray-500">视频列表</h1>
  2402. <div class="px-1">
  2403. <label>
  2404. <input
  2405. type="checkbox"
  2406. ?checked="${videoListSettings_default.allowAdvertisement}"
  2407. @change="${(e) => {
  2408. const el = e.target;
  2409. videoListSettings_default.allowAdvertisement = el.checked;
  2410. }}"
  2411. />
  2412. <span>允许广告</span>
  2413. </label>
  2414. <label class="flex items-center">
  2415. <span class="flex-none w-32">最短(含)</span>
  2416. <input
  2417. class="flex-auto border my-1 p-1"
  2418. type="text"
  2419. placeholder="HH:MM:SS"
  2420. value="${videoListSettings_default.durationGte.toTimeCode()}"
  2421. @input="${this.onVideListDurationGteChange}"
  2422. @keydown="${(e) => e.stopPropagation()}"
  2423. @blur="${() => {
  2424. this.onVideListDurationGteChange.flush();
  2425. }}"
  2426. @keyup="${(e) => {
  2427. if (e.key === "Enter") {
  2428. this.onVideListDurationGteChange(e);
  2429. this.onVideListDurationGteChange.flush();
  2430. }
  2431. }}"
  2432. />
  2433. </label>
  2434. <label class="flex items-center">
  2435. <span class="flex-none w-32">最长(不含)</span>
  2436. <input
  2437. class="flex-auto border my-1 p-1"
  2438. type="text"
  2439. placeholder="HH:MM:SS"
  2440. value="${videoListSettings_default.durationLt.toTimeCode()}"
  2441. @input="${this.onVideListDurationLtChange}"
  2442. @keydown="${(e) => e.stopPropagation()}"
  2443. @blur="${() => {
  2444. this.onVideListDurationLtChange.flush();
  2445. }}"
  2446. @keyup="${(e) => {
  2447. if (e.key === "Enter") {
  2448. this.onVideListDurationLtChange(e);
  2449. this.onVideListDurationLtChange.flush();
  2450. }
  2451. }}"
  2452. />
  2453. </label>
  2454. <label class="flex items-center">
  2455. <div class="flex-none w-32">排除关键词</div>
  2456. <div class="flex-auto">
  2457. <textarea
  2458. class="w-full border my-1 p-1"
  2459. placeholder=""
  2460. .value="${this.excludedKeywords}"
  2461. @input="${this.onExcludeKeywordInput}"
  2462. @keydown="${(e) => e.stopPropagation()}"
  2463. @focus="${(e) => growTextAreaHeight(e.target)}"
  2464. @blur=${() => {
  2465. this.excludedKeywordsBuffer = void 0;
  2466. }}
  2467. ></textarea>
  2468. <div class="text-gray-500 text-sm">
  2469. 不显示标题含关键词的视频。每行一个,不区分大小写。
  2470. </div>
  2471. </div>
  2472. </label>
  2473. </div>
  2474. </section>
  2475. `;
  2476. }
  2477. searchSettings() {
  2478. return html`
  2479. <section>
  2480. <h1 class="text-sm text-gray-500">搜索</h1>
  2481. <div class="px-1">
  2482. <label>
  2483. <input
  2484. type="checkbox"
  2485. ?checked="${searchSettings_default.strictTitleMatch}"
  2486. @change="${(e) => {
  2487. const el = e.target;
  2488. searchSettings_default.strictTitleMatch = el.checked;
  2489. }}"
  2490. />
  2491. <span>严格标题匹配</span>
  2492. </label>
  2493. <div class="text-gray-500 text-sm">
  2494. 标题必须包含所有关键词,屏蔽联想词和标签匹配
  2495. </div>
  2496. </div>
  2497. </section>
  2498. `;
  2499. }
  2500. userTable() {
  2501. const userIDs = blockedUsers_default.distinctID();
  2502. return html`
  2503. <div class="flex flex-col overflow-hidden max-h-[50vh]">
  2504. <h1 class="flex-none text-sm text-gray-500">
  2505. 已屏蔽用户 <span class="text-sm">(${userIDs.length})</span>
  2506. </h1>
  2507. <div class="flex-1 overflow-auto relative">
  2508. <table class="table-fixed border-separate border-spacing-2 w-full">
  2509. <thead class="sticky top-0">
  2510. <tr class="bg-gray-200 text-center">
  2511. <td>屏蔽时间</td>
  2512. <td>名称</td>
  2513. <td></td>
  2514. </tr>
  2515. </thead>
  2516. <tbody>
  2517. ${userIDs.map(blockedUsers_default.get).sort((a, b) => {
  2518. const dateCompare = compare(a.blockedAt, b.blockedAt);
  2519. if (dateCompare !== 0) {
  2520. return -dateCompare;
  2521. }
  2522. return compare(a.idAsNumber, b.idAsNumber);
  2523. }).map(({ id, name, blockedAt, rawBlockedAt }) => {
  2524. return html`
  2525. <tr class="group even:bg-gray-100">
  2526. <td class="text-right w-32">
  2527. ${rawBlockedAt ? html` <time datetime="${blockedAt.toISOString()}">
  2528. ${blockedAt.toLocaleString()}
  2529. </time>` : nothing}
  2530. </td>
  2531. <td class="text-center">${name}</td>
  2532. <td
  2533. class="transition opacity-0 group-hover:opacity-100 space-x-2 text-center"
  2534. >
  2535. <a
  2536. href="https://space.bilibili.com/${id}"
  2537. target="_blank"
  2538. class="inline-flex underline text-blue-500"
  2539. >
  2540. <svg
  2541. viewBox="0 0 24 24"
  2542. fill="none"
  2543. xmlns="http://www.w3.org/2000/svg"
  2544. class="h-[1.25em]"
  2545. >
  2546. <path fill-rule="evenodd" clip-rule="evenodd" d=${mdiOpenInNew} fill="currentColor">
  2547. </svg>
  2548. <span>个人空间</span>
  2549. </a>
  2550. <button
  2551. type="button"
  2552. @click=${() => blockedUsers_default.remove(id)}
  2553. class="inline-flex underline"
  2554. >
  2555. <svg
  2556. viewBox="0 0 24 24"
  2557. fill="none"
  2558. xmlns="http://www.w3.org/2000/svg"
  2559. class="h-[1.25em]"
  2560. >
  2561. <path fill-rule="evenodd" clip-rule="evenodd" d=${mdiAccountCheckOutline} fill="currentColor">
  2562. </svg>
  2563. <span>取消屏蔽</span>
  2564. </button>
  2565. </td>
  2566. </tr>
  2567. `;
  2568. })}
  2569. </tbody>
  2570. </table>
  2571. </div>
  2572. </div>
  2573. `;
  2574. }
  2575. liveRoomTable() {
  2576. const liveRoomIDs = blockedLiveRooms_default.distinctID();
  2577. return html`
  2578. <div class="flex flex-col overflow-hidden max-h-[50vh]">
  2579. <h1 class="flex-none text-sm text-gray-500">
  2580. 已屏蔽直播间 <span class="text-sm">(${liveRoomIDs.length})</span>
  2581. </h1>
  2582. <div class="flex-1 overflow-auto relative">
  2583. <table class="table-fixed border-separate border-spacing-2 w-full">
  2584. <thead class="sticky top-0">
  2585. <tr class="bg-gray-200 text-center">
  2586. <td>屏蔽时间</td>
  2587. <td>所有者</td>
  2588. <td></td>
  2589. </tr>
  2590. </thead>
  2591. <tbody>
  2592. ${liveRoomIDs.map(blockedLiveRooms_default.get).sort((a, b) => {
  2593. const dateCompare = compare(a.blockedAt, b.blockedAt);
  2594. if (dateCompare !== 0) {
  2595. return -dateCompare;
  2596. }
  2597. return compare(a.id, b.id);
  2598. }).map(({ id, owner, blockedAt }) => {
  2599. return html`
  2600. <tr class="group even:bg-gray-100">
  2601. <td class="text-right w-32">
  2602. <time datetime="${blockedAt.toISOString()}">
  2603. ${blockedAt.toLocaleString()}
  2604. </time>
  2605. </td>
  2606. <td class="text-center">${owner}</td>
  2607. <td
  2608. class="transition opacity-0 group-hover:opacity-100 space-x-2 text-center"
  2609. >
  2610. <a
  2611. href="https://live.bilibili.com/${id}"
  2612. target="_blank"
  2613. class="inline-flex underline text-blue-500"
  2614. >
  2615. <svg
  2616. viewBox="0 0 24 24"
  2617. fill="none"
  2618. xmlns="http://www.w3.org/2000/svg"
  2619. class="h-[1.25em]"
  2620. >
  2621. <path fill-rule="evenodd" clip-rule="evenodd" d=${mdiOpenInNew} fill="currentColor">
  2622. </svg>
  2623. <span>前往</span>
  2624. </a>
  2625. <button
  2626. type="button"
  2627. @click=${() => blockedLiveRooms_default.remove(id)}
  2628. class="inline-flex underline"
  2629. >
  2630. <svg
  2631. viewBox="0 0 24 24"
  2632. fill="none"
  2633. xmlns="http://www.w3.org/2000/svg"
  2634. class="h-[1.25em]"
  2635. >
  2636. <path fill-rule="evenodd" clip-rule="evenodd" d=${mdiCheck} fill="currentColor">
  2637. </svg>
  2638. <span>取消屏蔽</span>
  2639. </button>
  2640. </td>
  2641. </tr>
  2642. `;
  2643. })}
  2644. </tbody>
  2645. </table>
  2646. </div>
  2647. </div>
  2648. `;
  2649. }
  2650. };
  2651. __publicField(_SettingsDrawer, "id", `settings-${randomUUID()}`);
  2652. var SettingsDrawer = _SettingsDrawer;
  2653.  
  2654. // src/utils/isNonNull.ts
  2655. function isNonNull(v) {
  2656. return v != null;
  2657. }
  2658.  
  2659. // src/bilibili.com/components/FullHeaderButton.ts
  2660. var _FullHeaderButton = class _FullHeaderButton {
  2661. constructor(settings) {
  2662. __publicField(this, "settings");
  2663. __publicField(this, "render", () => {
  2664. const parent = document.querySelector(".right-entry");
  2665. if (!parent) {
  2666. return;
  2667. }
  2668. const container = obtainHTMLElementByID({
  2669. tag: "li",
  2670. id: _FullHeaderButton.id,
  2671. onDidCreate: (el) => {
  2672. el.classList.add("right-entry-item");
  2673. parent.prepend(...[parent.firstChild, el].filter(isNonNull));
  2674. }
  2675. });
  2676. render(
  2677. html`
  2678. <button
  2679. type="button"
  2680. class="right-entry__outside"
  2681. @click=${(e) => {
  2682. e.preventDefault();
  2683. e.stopPropagation();
  2684. this.settings.open();
  2685. }}
  2686. >
  2687. <svg viewBox="2 2 20 20" class="right-entry-icon" style="height: 20px; fill: currentColor;">
  2688. <path fill-rule="evenodd" clip-rule="evenodd" d=${mdiEyeOffOutline}>
  2689. </svg>
  2690. <span class="right-entry-text">屏蔽</span>
  2691. </button>
  2692. `,
  2693. container
  2694. );
  2695. });
  2696. this.settings = settings;
  2697. }
  2698. };
  2699. __publicField(_FullHeaderButton, "id", `full-header-button-${randomUUID()}`);
  2700. var FullHeaderButton = _FullHeaderButton;
  2701.  
  2702. // src/bilibili.com/models/migrate.ts
  2703. function migrateV1() {
  2704. return __async(this, null, function* () {
  2705. const key2 = "blockedUserIDs@7ced1613-89d7-4754-8989-2ad0d7cfa9db";
  2706. const oldValue = yield GM.getValue(key2);
  2707. if (!oldValue) {
  2708. return;
  2709. }
  2710. const newValue = {};
  2711. JSON.parse(String(oldValue)).forEach((i) => {
  2712. newValue[i] = true;
  2713. });
  2714. yield GM.setValue(
  2715. "blockedUsers@206ceed9-b514-4902-ad70-aa621fed5cd4",
  2716. JSON.stringify(newValue)
  2717. );
  2718. yield GM.deleteValue(key2);
  2719. });
  2720. }
  2721. function migrate() {
  2722. return __async(this, null, function* () {
  2723. yield migrateV1();
  2724. });
  2725. }
  2726.  
  2727. // src/bilibili.com/utils/parseUserURL.ts
  2728. function parseUserURL(rawURL) {
  2729. if (!rawURL) {
  2730. return;
  2731. }
  2732. const url = new URL(rawURL, window.location.href);
  2733. switch (url.host) {
  2734. case "space.bilibili.com": {
  2735. const match = /^\/(\d+)\/?/.exec(url.pathname);
  2736. if (!match) {
  2737. return;
  2738. }
  2739. return { id: match[1] };
  2740. }
  2741. case "cm.bilibili.com": {
  2742. const id = url.searchParams.get("space_mid");
  2743. if (id) {
  2744. return { id };
  2745. }
  2746. break;
  2747. }
  2748. default:
  2749. }
  2750. }
  2751.  
  2752. // src/bilibili.com/components/UserBlockButton.ts
  2753. var _UserBlockButton = class _UserBlockButton {
  2754. constructor(user) {
  2755. this.user = user;
  2756. __publicField(this, "render", () => {
  2757. const parent = document.querySelector(".h-action");
  2758. if (!parent) {
  2759. return;
  2760. }
  2761. const container = obtainHTMLElementByID({
  2762. tag: "div",
  2763. id: _UserBlockButton.id,
  2764. onDidCreate: (el) => {
  2765. el.style.display = "inline";
  2766. parent.append(...[el, parent.lastChild].filter(isNonNull));
  2767. }
  2768. });
  2769. const isBlocked = blockedUsers_default.has(this.user.id);
  2770. render(
  2771. html`
  2772. <span
  2773. class="h-f-btn"
  2774. @click=${(e) => {
  2775. var _a2, _b2;
  2776. e.stopPropagation();
  2777. blockedUsers_default.toggle({
  2778. id: this.user.id,
  2779. name: (_b2 = (_a2 = document.getElementById("h-name")) == null ? void 0 : _a2.innerText) != null ? _b2 : ""
  2780. });
  2781. }}
  2782. >
  2783. ${isBlocked ? "取消屏蔽" : "屏蔽"}
  2784. </span>
  2785. `,
  2786. container
  2787. );
  2788. });
  2789. }
  2790. };
  2791. __publicField(_UserBlockButton, "id", `user-block-button-${randomUUID()}`);
  2792. var UserBlockButton = _UserBlockButton;
  2793.  
  2794. // src/bilibili.com/utils/parseVideoURL.ts
  2795. function parseVideoURL(rawURL) {
  2796. if (!rawURL) {
  2797. return;
  2798. }
  2799. const url = new URL(rawURL, window.location.href);
  2800. if (url.host !== "www.bilibili.com") {
  2801. return;
  2802. }
  2803. const match = /^\/video\//.exec(url.pathname);
  2804. if (!match) {
  2805. return;
  2806. }
  2807. return {};
  2808. }
  2809.  
  2810. // src/utils/setHTMLElementDisplayHidden.ts
  2811. function setHTMLElementDisplayHidden(el, want) {
  2812. const actual = el.style.display === "none";
  2813. if (actual === want) {
  2814. return;
  2815. }
  2816. if (want) {
  2817. el.style.display = "none";
  2818. } else {
  2819. el.style.display = "";
  2820. }
  2821. }
  2822.  
  2823. // src/utils/injectStyle.ts
  2824. function injectStyle(id, css) {
  2825. obtainHTMLElementByID({
  2826. tag: "style",
  2827. id,
  2828. onDidCreate: (el) => {
  2829. document.head.appendChild(el);
  2830. el.innerHTML = css;
  2831. }
  2832. });
  2833. }
  2834.  
  2835. // src/bilibili.com/components/VideoHoverButton.ts
  2836. var VideoHoverButton = class {
  2837. constructor(parentNode, user) {
  2838. this.parentNode = parentNode;
  2839. this.user = user;
  2840. __publicField(this, "render", () => {
  2841. const { parentNode } = this;
  2842. if (!parentNode) {
  2843. return;
  2844. }
  2845. const parentKey = "dde57f95-0cb5-4443-bbeb-2466d63db0f1";
  2846. const key2 = "a1161956-2be7-4796-9f1b-528707156b11";
  2847. injectStyle(
  2848. parentKey,
  2849. `[data-${parentKey}]:hover [data-${key2}] {
  2850. filter: opacity(1);
  2851. transition: filter 0.2s linear 0.2s;
  2852. }
  2853.  
  2854. [data-${parentKey}] [data-${key2}] {
  2855. filter: opacity(0);
  2856. z-index: 10;
  2857. position: absolute;
  2858. top: 8px;
  2859. left: 8px;
  2860. transition: filter 0.2s linear 0s;
  2861. }
  2862. `
  2863. );
  2864. const el = obtainHTMLElementByDataKey({
  2865. tag: "div",
  2866. key: key2,
  2867. parentNode,
  2868. onDidCreate: (el2) => {
  2869. parentNode.setAttribute(`data-${parentKey}`, "");
  2870. parentNode.append(el2);
  2871. }
  2872. });
  2873. const isBlocked = blockedUsers_default.has(this.user.id);
  2874. render(
  2875. html`
  2876. <button
  2877. type="button"
  2878. title="${isBlocked ? "取消屏蔽此用户" : "屏蔽此用户"}"
  2879. class="rounded-md cursor-pointer z-20 border-none ${isBlocked ? "bg-white text-black" : "text-white bg-[rgba(33,33,33,.8)]"}"
  2880. @click=${(e) => {
  2881. e.preventDefault();
  2882. e.stopPropagation();
  2883. if (isBlocked) {
  2884. blockedUsers_default.remove(this.user.id);
  2885. } else {
  2886. blockedUsers_default.add(this.user);
  2887. }
  2888. }}
  2889. >
  2890. <svg viewBox="-3 -1 28 28" class="h-7 fill-current">
  2891. <path fill-rule="evenodd" clip-rule="evenodd" d=${isBlocked ? mdiAccountCheckOutline : mdiAccountCancelOutline}>
  2892. </svg>
  2893. </button>
  2894. `,
  2895. obtainStyledShadowRoot(el)
  2896. );
  2897. });
  2898. }
  2899. };
  2900.  
  2901. // src/bilibili.com/components/VideoDetailPatch.ts
  2902. var VideoDetailPatch = class {
  2903. constructor(ctx) {
  2904. this.ctx = ctx;
  2905. __publicField(this, "blockedTitles", /* @__PURE__ */ new Set());
  2906. __publicField(this, "render", () => {
  2907. document.querySelectorAll(".video-page-card-small").forEach((i) => {
  2908. var _a2, _b2, _c2, _d2, _e, _f, _g, _h;
  2909. const rawURL = (_a2 = i.querySelector(".upname a")) == null ? void 0 : _a2.getAttribute("href");
  2910. if (!rawURL) {
  2911. return;
  2912. }
  2913. const user = parseUserURL(rawURL);
  2914. let hidden = false;
  2915. if (user) {
  2916. const duration = (_d2 = (_c2 = (_b2 = i.querySelector(".duration")) == null ? void 0 : _b2.textContent) == null ? void 0 : _c2.trim()) != null ? _d2 : "";
  2917. const title = (_g = ((_e = i.querySelector(".title")) == null ? void 0 : _e.getAttribute("title")) || ((_f = i.querySelector(".title")) == null ? void 0 : _f.textContent)) != null ? _g : "";
  2918. hidden = this.ctx.shouldExcludeVideo({ user, duration, title });
  2919. if (hidden) {
  2920. this.blockedTitles.add(title);
  2921. }
  2922. } else {
  2923. hidden = !videoListSettings_default.allowAdvertisement;
  2924. }
  2925. setHTMLElementDisplayHidden(i, hidden);
  2926. if (user && !hidden) {
  2927. new VideoHoverButton(i.querySelector(".pic-box"), {
  2928. id: user.id,
  2929. name: ((_h = i.querySelector(".upname .name")) == null ? void 0 : _h.textContent) || user.id
  2930. }).render();
  2931. }
  2932. });
  2933. document.querySelectorAll(".bpx-player-ending-related-item").forEach((i) => {
  2934. var _a2;
  2935. const title = (_a2 = i.querySelector(
  2936. ".bpx-player-ending-related-item-title"
  2937. )) == null ? void 0 : _a2.textContent;
  2938. if (!title) {
  2939. return;
  2940. }
  2941. const hidden = this.blockedTitles.has(title) || this.ctx.shouldExcludeVideo({ title });
  2942. setHTMLElementDisplayHidden(i, hidden);
  2943. });
  2944. });
  2945. }
  2946. };
  2947.  
  2948. // src/bilibili.com/components/SSRVideoRankPatch.ts
  2949. var SSRVideoRankPatch = class {
  2950. constructor() {
  2951. __publicField(this, "render", () => {
  2952. document.querySelectorAll(".rank-item").forEach((i) => {
  2953. var _a2, _b2, _c2, _d2;
  2954. const user = parseUserURL(
  2955. (_b2 = (_a2 = i.querySelector(".up-name")) == null ? void 0 : _a2.parentElement) == null ? void 0 : _b2.getAttribute("href")
  2956. );
  2957. if (!user) {
  2958. return;
  2959. }
  2960. const name = (_d2 = (_c2 = i.querySelector(".up-name")) == null ? void 0 : _c2.textContent) != null ? _d2 : "";
  2961. const isBlocked = blockedUsers_default.has(user.id);
  2962. setHTMLElementDisplayHidden(i, isBlocked);
  2963. if (!isBlocked) {
  2964. new VideoHoverButton(i.querySelector(".img"), {
  2965. id: user.id,
  2966. name
  2967. }).render();
  2968. }
  2969. });
  2970. });
  2971. }
  2972. };
  2973.  
  2974. // src/utils/castPlainObject.ts
  2975. function castPlainObject(value) {
  2976. if (isPlainObject_default(value)) {
  2977. return value;
  2978. }
  2979. return { value };
  2980. }
  2981.  
  2982. // src/utils/evalInContentScope.ts
  2983. function evalInContentScope(javascript) {
  2984. try {
  2985. return JSON.parse(
  2986. window.eval(`JSON.stringify(eval(${JSON.stringify(javascript)}))`)
  2987. );
  2988. } catch (err) {
  2989. return err;
  2990. }
  2991. }
  2992.  
  2993. // src/utils/getElementSelector.ts
  2994. var attributeName = `data-select-${randomUUID()}`;
  2995. var nextValue = 1;
  2996. function getElementSelector(el) {
  2997. let v = el.getAttribute(attributeName);
  2998. if (!v) {
  2999. v = nextValue.toString();
  3000. nextValue += 1;
  3001. el.setAttribute(attributeName, v);
  3002. }
  3003. return `[${attributeName}='${v}']`;
  3004. }
  3005.  
  3006. // src/bilibili.com/components/VueVideoRankPatch.ts
  3007. var VueVideoRankPatch = class {
  3008. constructor() {
  3009. __publicField(this, "render", () => {
  3010. document.querySelectorAll(".video-card").forEach((i) => {
  3011. const selector = getElementSelector(i);
  3012. const videoData = evalInContentScope(
  3013. `document.querySelector(${JSON.stringify(
  3014. selector
  3015. )}).__vue__._props.videoData`
  3016. );
  3017. const { owner } = castPlainObject(videoData);
  3018. const { mid, name } = castPlainObject(owner);
  3019. if (typeof mid !== "number" || typeof name !== "string") {
  3020. return;
  3021. }
  3022. const userID = mid.toString();
  3023. const isBlocked = blockedUsers_default.has(userID);
  3024. setHTMLElementDisplayHidden(i, isBlocked);
  3025. if (!isBlocked) {
  3026. new VideoHoverButton(i.querySelector(".video-card__content"), {
  3027. id: userID,
  3028. name
  3029. }).render();
  3030. }
  3031. });
  3032. });
  3033. }
  3034. };
  3035.  
  3036. // src/bilibili.com/components/VideoListPatch.ts
  3037. var _VideoListPatch = class _VideoListPatch {
  3038. constructor(ctx) {
  3039. this.ctx = ctx;
  3040. __publicField(this, "disabled", false);
  3041. __publicField(this, "render", () => {
  3042. let matchCount = 0;
  3043. let listEl;
  3044. document.querySelectorAll(".bili-video-card").forEach((i) => {
  3045. var _a2, _b2, _c2, _d2, _e, _f, _g, _h, _i;
  3046. const rawURL = (_a2 = i.querySelector("a.bili-video-card__info--owner")) == null ? void 0 : _a2.getAttribute("href");
  3047. if (!rawURL) {
  3048. return;
  3049. }
  3050. const user = parseUserURL(rawURL);
  3051. let match = false;
  3052. if (user) {
  3053. const duration = (_d2 = (_c2 = (_b2 = i.querySelector(".bili-video-card__stats__duration")) == null ? void 0 : _b2.textContent) == null ? void 0 : _c2.trim()) != null ? _d2 : "";
  3054. const title = (_g = ((_e = i.querySelector(".bili-video-card__info--tit")) == null ? void 0 : _e.getAttribute("title")) || ((_f = i.querySelector(".bili-video-card__info--tit")) == null ? void 0 : _f.textContent)) != null ? _g : "";
  3055. match = this.ctx.shouldExcludeVideo({ user, duration, title });
  3056. } else {
  3057. match = !videoListSettings_default.allowAdvertisement;
  3058. }
  3059. if (match) {
  3060. matchCount += 1;
  3061. }
  3062. let container = i;
  3063. while (((_h = container.parentElement) == null ? void 0 : _h.childElementCount) === 1) {
  3064. container = container.parentElement;
  3065. }
  3066. listEl = container.parentElement || void 0;
  3067. const hidden = !this.disabled && match;
  3068. setHTMLElementDisplayHidden(container, hidden);
  3069. if (user && !hidden) {
  3070. new VideoHoverButton(i.querySelector(".bili-video-card__image--wrap"), {
  3071. id: user.id,
  3072. name: ((_i = i.querySelector(".bili-video-card__info--author")) == null ? void 0 : _i.textContent) || user.id
  3073. }).render();
  3074. }
  3075. });
  3076. render(
  3077. matchCount === 0 ? nothing : html`
  3078. <div class="w-full text-gray-500 text-center m-1">
  3079. ${this.disabled ? html`${matchCount} 条视频符合屏蔽规则` : html`已屏蔽 ${matchCount} 条视频`}
  3080. <button
  3081. type="button"
  3082. class="border rounded py-1 px-2 text-black hover:bg-gray-200 transition ease-in-out duration-200"
  3083. @click=${() => {
  3084. this.disabled = !this.disabled;
  3085. }}
  3086. >
  3087. ${this.disabled ? "屏蔽" : "全部显示"}
  3088. </button>
  3089. </div>
  3090. `,
  3091. obtainStyledShadowRoot(
  3092. obtainHTMLElementByID({
  3093. id: `video-list-patch-status-${_VideoListPatch.id}`,
  3094. tag: "div",
  3095. onDidCreate: (el) => {
  3096. var _a2;
  3097. (_a2 = listEl == null ? void 0 : listEl.parentElement) == null ? void 0 : _a2.insertBefore(el, listEl);
  3098. }
  3099. })
  3100. )
  3101. );
  3102. });
  3103. }
  3104. };
  3105. __publicField(_VideoListPatch, "id", randomUUID());
  3106. var VideoListPatch = _VideoListPatch;
  3107.  
  3108. // src/bilibili.com/components/AdblockTipPatch.ts
  3109. var AdblockTipPatch = class {
  3110. constructor() {
  3111. __publicField(this, "render", () => {
  3112. const el = document.querySelector(".adblock-tips");
  3113. if (el instanceof HTMLElement) {
  3114. setHTMLElementDisplayHidden(el, !homePageSettings_default.allowAdblockTips);
  3115. }
  3116. });
  3117. }
  3118. };
  3119.  
  3120. // src/bilibili.com/components/HomePageFloorCardHoverButton.ts
  3121. var HomePageFloorCardHoverButton = class {
  3122. constructor(parentNode, floorCard) {
  3123. this.parentNode = parentNode;
  3124. this.floorCard = floorCard;
  3125. __publicField(this, "render", () => {
  3126. const { parentNode } = this;
  3127. if (!parentNode) {
  3128. return;
  3129. }
  3130. const parentKey = "51d5da07-ab2d-4342-8496-c3c53980bb74";
  3131. const key2 = "85e3e435-2ad2-4a7d-839f-69318799db0f";
  3132. injectStyle(
  3133. parentKey,
  3134. `[data-${parentKey}]:hover [data-${key2}] {
  3135. filter: opacity(1);
  3136. transition: filter 0.2s linear 0.2s;
  3137. }
  3138.  
  3139. [data-${parentKey}] [data-${key2}] {
  3140. filter: opacity(0);
  3141. z-index: 10;
  3142. position: absolute;
  3143. top: 8px;
  3144. left: 8px;
  3145. transition: filter 0.2s linear 0s;
  3146. }
  3147. `
  3148. );
  3149. const el = obtainHTMLElementByDataKey({
  3150. tag: "div",
  3151. key: key2,
  3152. parentNode,
  3153. onDidCreate: (el2) => {
  3154. parentNode.setAttribute(`data-${parentKey}`, "");
  3155. parentNode.append(el2);
  3156. }
  3157. });
  3158. render(
  3159. html`
  3160. <button
  3161. type="button"
  3162. title="屏蔽此频道的楼层卡片"
  3163. class="absolute top-2 left-2 rounded-md cursor-pointer text-white bg-[rgba(33,33,33,.8)] z-20 border-none"
  3164. @click=${(e) => {
  3165. e.preventDefault();
  3166. e.stopPropagation();
  3167. homePageSettings_default.floorCard.excludeByChannel = [
  3168. ...homePageSettings_default.floorCard.excludeByChannel,
  3169. this.floorCard.channel
  3170. ];
  3171. }}
  3172. >
  3173. <svg viewBox="-2 -2 28 28" class="h-7 fill-current">
  3174. <path fill-rule="evenodd" clip-rule="evenodd" d=${mdiEyeOff}>
  3175. </svg>
  3176. </button>
  3177. `,
  3178. obtainStyledShadowRoot(el)
  3179. );
  3180. });
  3181. }
  3182. };
  3183.  
  3184. // src/bilibili.com/components/HomePageFloorCardPatch.ts
  3185. var HomePageFloorCardPatch = class {
  3186. constructor() {
  3187. __publicField(this, "render", () => {
  3188. document.querySelectorAll(".floor-single-card").forEach((el) => {
  3189. var _a2, _b2;
  3190. const channel = (_b2 = (_a2 = el.querySelector(".floor-title")) == null ? void 0 : _a2.textContent) == null ? void 0 : _b2.trim();
  3191. if (!channel) {
  3192. return;
  3193. }
  3194. const i = { channel };
  3195. const hidden = homePageSettings_default.floorCard.shouldExclude(i);
  3196. setHTMLElementDisplayHidden(el, hidden);
  3197. if (!hidden) {
  3198. new HomePageFloorCardHoverButton(
  3199. el.querySelector(".cover-container"),
  3200. i
  3201. ).render();
  3202. }
  3203. });
  3204. });
  3205. }
  3206. };
  3207.  
  3208. // src/utils/ExactSearchMatcher.ts
  3209. var ExactSearchMatcher = class {
  3210. constructor(q) {
  3211. __publicField(this, "keywords");
  3212. __publicField(this, "match", (...searchKey) => {
  3213. if (this.keywords.length === 0) {
  3214. return true;
  3215. }
  3216. return this.keywords.every((i) => {
  3217. return searchKey.some((j) => j.toLowerCase().includes(i));
  3218. });
  3219. });
  3220. this.keywords = q.split(/\s/).map((i) => i.trim().toLowerCase()).filter((i) => i);
  3221. }
  3222. };
  3223.  
  3224. // src/bilibili.com/Context.ts
  3225. var Context = class {
  3226. constructor({ query }) {
  3227. __publicField(this, "m");
  3228. __publicField(this, "query");
  3229. __publicField(this, "shouldExcludeVideo", (v) => {
  3230. if (v.user && blockedUsers_default.has(v.user.id)) {
  3231. return true;
  3232. }
  3233. if (v.duration) {
  3234. const durationMs = Duration.cast(v.duration).toMilliseconds();
  3235. if (durationMs <= 0) {
  3236. } else if (videoListSettings_default.durationGte.valid && !(durationMs >= videoListSettings_default.durationGte.toMilliseconds())) {
  3237. return true;
  3238. } else if (videoListSettings_default.durationLt.valid && !(durationMs < videoListSettings_default.durationLt.toMilliseconds())) {
  3239. return true;
  3240. }
  3241. }
  3242. if (this.query && v.title && searchSettings_default.strictTitleMatch) {
  3243. if (!this.m.match(v.title)) {
  3244. return true;
  3245. }
  3246. }
  3247. if (v.title && videoListSettings_default.excludeKeywords.some(
  3248. (i) => v.title.toLowerCase().includes(i.toLowerCase())
  3249. )) {
  3250. return true;
  3251. }
  3252. return false;
  3253. });
  3254. __publicField(this, "shouldExcludeLiveRoom", (v) => {
  3255. if (v.owner && blockedUsers_default.has(v.owner.id)) {
  3256. return true;
  3257. }
  3258. if (v.room && blockedLiveRooms_default.has(v.room.id)) {
  3259. return true;
  3260. }
  3261. return false;
  3262. });
  3263. this.query = query;
  3264. this.m = new ExactSearchMatcher(query);
  3265. }
  3266. };
  3267.  
  3268. // src/bilibili.com/components/MiniHeaderButton.ts
  3269. var _MiniHeaderButton = class _MiniHeaderButton {
  3270. constructor(settings) {
  3271. __publicField(this, "settings");
  3272. __publicField(this, "render", () => {
  3273. const parent = document.querySelector(
  3274. ".nav-user-center .user-con:nth-child(2)"
  3275. );
  3276. if (!parent) {
  3277. return;
  3278. }
  3279. const container = obtainHTMLElementByID({
  3280. tag: "div",
  3281. id: _MiniHeaderButton.id,
  3282. onDidCreate: (el) => {
  3283. el.classList.add("item");
  3284. parent.prepend(...[parent.firstChild, el].filter(isNonNull));
  3285. }
  3286. });
  3287. render(
  3288. html`
  3289. <div
  3290. @click=${(e) => {
  3291. e.preventDefault();
  3292. e.stopPropagation();
  3293. this.settings.open();
  3294. }}
  3295. >
  3296. <span class="name">屏蔽</span>
  3297. </div>
  3298. `,
  3299. container
  3300. );
  3301. });
  3302. this.settings = settings;
  3303. }
  3304. };
  3305. __publicField(_MiniHeaderButton, "id", `mini-header-button-${randomUUID()}`);
  3306. var MiniHeaderButton = _MiniHeaderButton;
  3307.  
  3308. // src/bilibili.com/components/PlaylistPatch.ts
  3309. var PlaylistPatch = class {
  3310. constructor(ctx) {
  3311. this.ctx = ctx;
  3312. __publicField(this, "render", () => {
  3313. document.querySelectorAll(".video-card").forEach((i) => {
  3314. var _a2, _b2, _c2, _d2, _e, _f, _g, _h;
  3315. const rawURL = (_a2 = i.querySelector("a.upname")) == null ? void 0 : _a2.getAttribute("href");
  3316. if (!rawURL) {
  3317. return;
  3318. }
  3319. const user = parseUserURL(rawURL);
  3320. let hidden = false;
  3321. if (user) {
  3322. const duration = (_d2 = (_c2 = (_b2 = i.querySelector(".duration")) == null ? void 0 : _b2.textContent) == null ? void 0 : _c2.trim()) != null ? _d2 : "";
  3323. const title = (_g = ((_e = i.querySelector(".title")) == null ? void 0 : _e.getAttribute("title")) || ((_f = i.querySelector(".title")) == null ? void 0 : _f.textContent)) != null ? _g : "";
  3324. hidden = this.ctx.shouldExcludeVideo({ user, duration, title });
  3325. } else {
  3326. hidden = !videoListSettings_default.allowAdvertisement;
  3327. }
  3328. setHTMLElementDisplayHidden(i, hidden);
  3329. if (user && !hidden) {
  3330. new VideoHoverButton(i.querySelector(".pic-box"), {
  3331. id: user.id,
  3332. name: ((_h = i.querySelector(".upname .name")) == null ? void 0 : _h.textContent) || user.id
  3333. }).render();
  3334. }
  3335. });
  3336. });
  3337. }
  3338. };
  3339.  
  3340. // src/bilibili.com/utils/parseLiveRoomURL.ts
  3341. function parseLiveRoomURL(rawURL) {
  3342. if (!rawURL) {
  3343. return;
  3344. }
  3345. const url = new URL(rawURL, window.location.href);
  3346. switch (url.host) {
  3347. case "live.bilibili.com": {
  3348. const match = /^\/(\d+)\/?/.exec(url.pathname);
  3349. if (!match) {
  3350. return;
  3351. }
  3352. return { id: match[1] };
  3353. }
  3354. default:
  3355. }
  3356. }
  3357.  
  3358. // src/bilibili.com/components/LiveRoomHoverButton.ts
  3359. var LiveRoomHoverButton = class {
  3360. constructor(parentNode, room) {
  3361. this.parentNode = parentNode;
  3362. this.room = room;
  3363. __publicField(this, "render", () => {
  3364. const { parentNode } = this;
  3365. if (!parentNode) {
  3366. return;
  3367. }
  3368. const parentKey = "321c1408-3ba8-4f8e-8ec8-4c491cf648c6";
  3369. const key2 = "c2ad7200-7141-46cd-a0ce-ba71ca52e396";
  3370. injectStyle(
  3371. parentKey,
  3372. `[data-${parentKey}]:hover [data-${key2}] {
  3373. filter: opacity(1);
  3374. transition: filter 0.2s linear 0.2s;
  3375. }
  3376.  
  3377. [data-${parentKey}] [data-${key2}] {
  3378. filter: opacity(0);
  3379. z-index: 10;
  3380. position: absolute;
  3381. top: 8px;
  3382. left: 8px;
  3383. transition: filter 0.2s linear 0s;
  3384. }
  3385. `
  3386. );
  3387. const el = obtainHTMLElementByDataKey({
  3388. tag: "div",
  3389. key: key2,
  3390. parentNode,
  3391. onDidCreate: (el2) => {
  3392. parentNode.setAttribute(`data-${parentKey}`, "");
  3393. parentNode.append(el2);
  3394. }
  3395. });
  3396. const isBlocked = blockedLiveRooms_default.has(this.room.id);
  3397. render(
  3398. html`
  3399. <button
  3400. type="button"
  3401. title="${isBlocked ? "取消屏蔽此直播间" : "屏蔽此直播间"}"
  3402. class="absolute top-2 left-2 p-1 rounded-md cursor-pointer isolate border-none ${isBlocked ? "bg-white text-black" : "text-white bg-[rgba(33,33,33,.8)]"}"
  3403. style="z-index: 200;"
  3404. @click=${(e) => {
  3405. e.preventDefault();
  3406. e.stopPropagation();
  3407. blockedLiveRooms_default.toggle(this.room, !isBlocked);
  3408. }}
  3409. >
  3410. <svg viewBox="0 0 24 24" class="h-8 fill-current">
  3411. <path fill-rule="evenodd" clip-rule="evenodd" d=${isBlocked ? mdiCheckCircleOutline : mdiCancel}>
  3412. </svg>
  3413. </button>
  3414. `,
  3415. obtainStyledShadowRoot(el)
  3416. );
  3417. });
  3418. }
  3419. };
  3420.  
  3421. // src/bilibili.com/components/LiveRoomListPatch.ts
  3422. var _LiveRoomPatch = class _LiveRoomPatch {
  3423. constructor(ctx) {
  3424. this.ctx = ctx;
  3425. __publicField(this, "disabled", false);
  3426. __publicField(this, "render", () => {
  3427. let matchCount = 0;
  3428. let listEl;
  3429. document.querySelectorAll("a#card").forEach((i) => {
  3430. var _a2, _b2;
  3431. const rawURL = i.getAttribute("href");
  3432. if (!rawURL) {
  3433. return;
  3434. }
  3435. const room = parseLiveRoomURL(rawURL);
  3436. if (!room) {
  3437. return;
  3438. }
  3439. const match = this.ctx.shouldExcludeLiveRoom({ room });
  3440. if (match) {
  3441. matchCount += 1;
  3442. }
  3443. let container = i;
  3444. while (((_a2 = container.parentElement) == null ? void 0 : _a2.childElementCount) === 1) {
  3445. container = container.parentElement;
  3446. }
  3447. listEl = container.parentElement || void 0;
  3448. const hidden = !this.disabled && match;
  3449. setHTMLElementDisplayHidden(container, hidden);
  3450. if (!hidden) {
  3451. new LiveRoomHoverButton(i.querySelector(".Item_cover-wrap_BmU4h"), {
  3452. id: room.id,
  3453. owner: ((_b2 = i.querySelector(".Item_nickName_KO2QE")) == null ? void 0 : _b2.textContent) || room.id
  3454. }).render();
  3455. }
  3456. });
  3457. render(
  3458. matchCount === 0 ? nothing : html`
  3459. <div class="w-full text-gray-500 text-center m-1">
  3460. ${this.disabled ? html`${matchCount} 个直播间符合屏蔽规则` : html`已屏蔽 ${matchCount} 个直播间`}
  3461. <button
  3462. type="button"
  3463. class="border rounded py-1 px-2 text-black hover:bg-gray-200 transition ease-in-out duration-200"
  3464. @click=${() => {
  3465. this.disabled = !this.disabled;
  3466. }}
  3467. >
  3468. ${this.disabled ? "屏蔽" : "全部显示"}
  3469. </button>
  3470. </div>
  3471. `,
  3472. obtainStyledShadowRoot(
  3473. obtainHTMLElementByID({
  3474. id: `live-room-list-patch-status-${_LiveRoomPatch.id}`,
  3475. tag: "div",
  3476. onDidCreate: (el) => {
  3477. var _a2;
  3478. (_a2 = listEl == null ? void 0 : listEl.parentElement) == null ? void 0 : _a2.insertBefore(el, listEl);
  3479. }
  3480. })
  3481. )
  3482. );
  3483. });
  3484. }
  3485. };
  3486. __publicField(_LiveRoomPatch, "id", randomUUID());
  3487. var LiveRoomPatch = _LiveRoomPatch;
  3488.  
  3489. // src/bilibili.com/components/LiveHeaderButton.ts
  3490. var _LiveHeaderButton = class _LiveHeaderButton {
  3491. constructor(settings) {
  3492. __publicField(this, "settings");
  3493. __publicField(this, "render", () => {
  3494. const parent = document.querySelector(".link-navbar");
  3495. if (!parent) {
  3496. return;
  3497. }
  3498. const container = obtainHTMLElementByID({
  3499. tag: "div",
  3500. id: _LiveHeaderButton.id,
  3501. onDidCreate: (el) => {
  3502. el.style.fontSize = "14px";
  3503. parent.append(...[el, parent.lastChild].filter(isNonNull));
  3504. }
  3505. });
  3506. render(
  3507. html`
  3508. <div
  3509. style="display: flex; align-items: center; margin: 0 20px;flex-direction: column;gap: 4px;padding: 12px;font-size: 14px; cursor: pointer;"
  3510. @click=${(e) => {
  3511. e.preventDefault();
  3512. e.stopPropagation();
  3513. this.settings.open();
  3514. }}
  3515. >
  3516. <svg viewBox="2 2 20 20" style="height: 20px; fill: currentColor;">
  3517. <path fill-rule="evenodd" clip-rule="evenodd" d=${mdiEyeOffOutline}>
  3518. </svg>
  3519. <span>屏蔽</span>
  3520. </div>
  3521. `,
  3522. container
  3523. );
  3524. });
  3525. this.settings = settings;
  3526. }
  3527. };
  3528. __publicField(_LiveHeaderButton, "id", `live-header-button-${randomUUID()}`);
  3529. var LiveHeaderButton = _LiveHeaderButton;
  3530.  
  3531. // src/bilibili.com/block.user.ts
  3532. function createApp() {
  3533. return __async(this, null, function* () {
  3534. var _a2;
  3535. const rawURL = window.location.href;
  3536. const settings = new SettingsDrawer();
  3537. const components = [settings];
  3538. const user = parseUserURL(rawURL);
  3539. const url = new URL(rawURL);
  3540. let headerButton;
  3541. yield waitUntil({
  3542. ready: () => {
  3543. var _a3, _b2, _c2, _d2;
  3544. if (((_b2 = (_a3 = document.querySelector(".right-entry")) == null ? void 0 : _a3.childElementCount) != null ? _b2 : 0) >= 2) {
  3545. headerButton = new FullHeaderButton(settings);
  3546. return true;
  3547. }
  3548. if (((_d2 = (_c2 = document.querySelector(".nav-user-center .user-con:nth-child(2)")) == null ? void 0 : _c2.childElementCount) != null ? _d2 : 0) >= 2) {
  3549. headerButton = new MiniHeaderButton(settings);
  3550. return true;
  3551. }
  3552. if (document.querySelector(".link-navbar .right-part")) {
  3553. headerButton = new LiveHeaderButton(settings);
  3554. return true;
  3555. }
  3556. return false;
  3557. }
  3558. });
  3559. if (headerButton) {
  3560. components.push(headerButton);
  3561. }
  3562. const data = {
  3563. query: ""
  3564. };
  3565. if (url.host === "search.bilibili.com") {
  3566. data.query = (_a2 = url.searchParams.get("keyword")) != null ? _a2 : "";
  3567. }
  3568. const ctx = new Context(data);
  3569. if (user) {
  3570. components.push(new UserBlockButton(user));
  3571. } else if (parseVideoURL(rawURL)) {
  3572. components.push(new VideoDetailPatch(ctx));
  3573. } else if (url.host === "www.bilibili.com" && url.pathname.startsWith("/v/popular/rank/all")) {
  3574. components.push(new SSRVideoRankPatch());
  3575. } else if (url.host === "www.bilibili.com" && url.pathname.startsWith("/v/popular/")) {
  3576. components.push(new VueVideoRankPatch());
  3577. } else if (url.host === "www.bilibili.com" && url.pathname.startsWith("/list/")) {
  3578. components.push(new PlaylistPatch(ctx));
  3579. } else if (url.host === "live.bilibili.com") {
  3580. components.push(new LiveRoomPatch(ctx), new VideoListPatch(ctx));
  3581. } else {
  3582. components.push(new VideoListPatch(ctx));
  3583. }
  3584. if (url.host === "www.bilibili.com" && url.pathname === "/") {
  3585. components.push(new AdblockTipPatch(), new HomePageFloorCardPatch());
  3586. }
  3587. return {
  3588. render: () => components.forEach((i) => i.render())
  3589. };
  3590. });
  3591. }
  3592. function routeKey() {
  3593. var _a2;
  3594. const { host, pathname, search } = window.location;
  3595. if (host === "search.bilibili.com") {
  3596. const q = new URLSearchParams(search);
  3597. return `search:${(_a2 = q.get("keyword")) != null ? _a2 : ""}`;
  3598. }
  3599. return pathname;
  3600. }
  3601. function main() {
  3602. return __async(this, null, function* () {
  3603. yield migrate();
  3604. const initialRouteKey = routeKey();
  3605. const app = yield createApp();
  3606. const d2 = new Disposal();
  3607. d2.push(
  3608. new Polling({
  3609. update: () => {
  3610. if (routeKey() !== initialRouteKey) {
  3611. d2.dispose();
  3612. main();
  3613. return;
  3614. }
  3615. app.render();
  3616. },
  3617. scheduleNext: (update) => setTimeout(update, 100)
  3618. })
  3619. );
  3620. });
  3621. }
  3622. onDocumentReadyOnce(main);
  3623. })();
  3624. /*! Bundled license information:
  3625.  
  3626. lit-html/development/lit-html.js:
  3627. (**
  3628. * @license
  3629. * Copyright 2017 Google LLC
  3630. * SPDX-License-Identifier: BSD-3-Clause
  3631. *)
  3632.  
  3633. lodash-es/lodash.js:
  3634. (**
  3635. * @license
  3636. * Lodash (Custom Build) <https://lodash.com/>
  3637. * Build: `lodash modularize exports="es" -o ./`
  3638. * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
  3639. * Released under MIT license <https://lodash.com/license>
  3640. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  3641. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  3642. *)
  3643. */