DimitarSerg

Untitled

Jun 28th, 2023
967
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /***/ 909:
  2. /***/ (function(module, exports, __webpack_require__) {
  3.  
  4. "use strict";
  5.  
  6. Object.defineProperty(exports, "__esModule", { value: true });
  7. exports.parseMetaTooltip = void 0;
  8. const parseMetaTooltip = (linksLength = 1) => {
  9.     var _a, _b, _c;
  10.     try {
  11.         const selectors = {
  12.             cover: [
  13.                 { selector: 'meta[property="twitter:image"]', attribute: 'content' },
  14.                 { selector: 'meta[property="og:image"]', attribute: 'content' },
  15.                 { selector: 'meta[itemprop="image"]', attribute: 'content' },
  16.                 { selector: 'meta[itemprop="image"]', attribute: 'content' }
  17.             ],
  18.             title: [
  19.                 { selector: 'meta[property="twitter:title"]', attribute: 'content' },
  20.                 { selector: 'meta[property="og:title"]', attribute: 'content' },
  21.                 { selector: 'meta[itemprop="name"]', attribute: 'content' },
  22.                 { selector: 'title', content: 1 },
  23.                 { selector: 'h1', content: 1 }
  24.             ]
  25.         };
  26.         const resp = Object.entries(selectors).reduce((a, [name, selectors]) => {
  27.             const current = selectors
  28.                 .map((e) => {
  29.                 const element = document.querySelector(e.selector);
  30.                 return (element &&
  31.                     ((e.attribute && element.getAttribute(e.attribute)) || (e.content && (element.textContent || '').trim())));
  32.             })
  33.                 .filter((e) => e)[0];
  34.             return { ...a, [name]: current };
  35.         }, {});
  36.         try {
  37.             const YT_REGEXP = /^(?:https?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})(?:\S+)?$/;
  38.             if (YT_REGEXP.test(window.location.href)) {
  39.                 const id = (_a = window.location.href.match(YT_REGEXP)) === null || _a === void 0 ? void 0 : _a[1];
  40.                 resp.cover = `https://i.ytimg.com/vi/${id}/hqdefault.jpg`;
  41.                 resp.title = (_c = (_b = document.querySelector('h1')) === null || _b === void 0 ? void 0 : _b.textContent) === null || _c === void 0 ? void 0 : _c.trim();
  42.                 resp.url = `https://www.youtube.com/watch?v=${id}`;
  43.             }
  44.         }
  45.         catch (e) { }
  46.         resp.weight = 1 / linksLength;
  47.         return resp;
  48.     }
  49.     catch (e) {
  50.         console.error(e);
  51.         return {};
  52.     }
  53. };
  54. exports.parseMetaTooltip = parseMetaTooltip;
Advertisement
Add Comment
Please, Sign In to add comment