### Handle Speech Recognition Start Source: https://github.com/microlinkhq/metascraper/blob/master/packages/metascraper/test/integration/yahoo-news/input.html Initializes recognition and starts the recognition process. Sets the recognition start flag. ```javascript a.recognitionInit(a), a.startRecognition(a) ``` -------------------------------- ### Initialize Benji Start Function Source: https://github.com/microlinkhq/metascraper/blob/master/packages/metascraper/test/integration/yahoo-news/input.html Defines the `runBenji` function to start the Benji service with a given configuration. If Benji is already defined, it calls `start`; otherwise, it initializes Benji with the provided config. ```javascript function runBenji(config) { if (typeof window.benji !== 'undefined') { window.benji.start(config); } else { window.benji = { config: config, }; } } ``` -------------------------------- ### Get Performance Start Time Source: https://github.com/microlinkhq/metascraper/blob/master/packages/metascraper/test/integration/forbes/input.html Returns the current performance start time. ```javascript function c() { return i } ``` -------------------------------- ### YouTube Player Initialization and Configuration Source: https://github.com/microlinkhq/metascraper/blob/master/packages/metascraper-youtube/test/fixtures/youtube-title.html This snippet handles the initial setup and configuration of the YouTube player. It selects the player container, retrieves necessary configuration objects, and attempts to create the player instance. ```javascript if (window.ytcsi) {window.ytcsi.tick('gcc', null, '');}(function() {var element = document.querySelector('#player-placeholder'); if (element && element.remove && typeof element.remove === 'function') {element.remove();}})(); ``` ```javascript if (window.ytcsi) {window.ytcsi.tick('bs', null, '');}ytcfg.set('initialBodyClientWidth', document.body.clientWidth);if (window.ytcsi) {window.ytcsi.tick('ai', null, '');} ``` -------------------------------- ### Event Listener Setup Source: https://github.com/microlinkhq/metascraper/blob/master/packages/metascraper/test/integration/yahoo-news/input.html Sets up event listeners for 'keydown' and 'click' events. It also includes logic for handling 'animationend' and 'animationcancel' events. ```javascript addEventListener("keydown",M),p.addEventListener("click",N)),t&&(t.addEventListener("animationend",(function(e){R(e)})),t.addEventListener("animationcancel",(function(e){R(e)}))) ``` -------------------------------- ### Install metascraper-title Source: https://github.com/microlinkhq/metascraper/blob/master/packages/metascraper-title/README.md Install the metascraper-title package using npm. This package is used to get the title property from HTML markup. ```bash $ npm install metascraper-title --save ``` -------------------------------- ### Load Pushly SDK Source: https://github.com/microlinkhq/metascraper/blob/master/packages/metascraper/test/integration/itpro/input.html Initialize the Pushly SDK by calling the `pushly` function with the 'load' command and your domain key. Ensure the SDK script is correctly referenced. ```javascript window.PushlySDK=window.PushlySDK||[];function pushly(){window.PushlySDK.push(arguments)}pushly("load",{domainKey:"NexYwVKgzaAjnOVAEHxy467LsVumN5DnDUoM",sw:"/media/shared/js/pushly-sdk-worker.js"}); ``` -------------------------------- ### Get Navigation Start Time Source: https://github.com/microlinkhq/metascraper/blob/master/packages/metascraper/test/integration/yahoo-news/input.html Retrieves the navigation start time from the browser's performance timing API. Initializes 'ee' with this value. ```javascript re=function(){var e;te=ne(),window.performance&&window.performance.timing&&window.performance.timing.navigationStart&&(e=window.performance.timing.navigationStart,ee=e) ``` -------------------------------- ### Event Listener Setup Source: https://github.com/microlinkhq/metascraper/blob/master/packages/metascraper-amazon/test/fixtures/amazon-com/ansi-url.html Sets up various event listeners for mouse movements, clicks, and visibility changes. Includes functions for adding and removing event listeners. ```javascript (function(u,w,K){var m=function(a,c,b,f){a.addEventListener?a.addEventListener(c,b,f):a.attachEvent&&a.attachEvent("on"+c,b)},p=function(a,c,b,f){document.removeEventListener?a.removeEventListener(c,b,f||!1):document.detachEvent&&a.detachEvent("on"+c,b)},y=function(a){var c;a=a.document;"undefined"!==typeof a.hidden?c="visibilitychange":"undefined"!==typeof a.mozHidden?c="mozvisibilitychange":"undefined"!==typeof a.msHidden?c="msvisibilitychange":"undefined"!==typeof a.webkitHidden&&(c="webkitvisibilitychange"); return c},D=function(a,c){var b=y(a),f=a.document;b&&m(f,b,c,!1)},x=function(a){try{for(var c=Array.prototype.slice.call(arguments,1),b=0;b1?r-1:0),i=1;i1?o:o[0]}}(t,...n)}}))}var g=r(2825);const m=e=\u003e{const t=e.startsWith(\ ``` ```javascript http\\ ``` ```javascript \ ``` ```javascript e+=\ ``` ```javascript /\\ ``` ```javascript \ ``` ```javascript r.p=t?e:\ ``` ```javascript https:// ``` ```javascript \ ``` ```javascript +e};let v=!1;function b(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},b=arguments.length>2?arguments[2]:void 0,y=arguments.length>3?arguments[3]:void 0,{init:A,info:w,loader_config:x,runtime:E={loaderType:b},exposed:_=!0}=t;w||(A=T.init,w=T.info,x=T.loader_config),(0,i.Dg)(e.agentIdentifier,A||{}),(0,i.GE)(e.agentIdentifier,x||{}),w.jsAttributes??={},d.v6&& (w.jsAttributes.isWorker=!0),(0,i.CX)(e.agentIdentifier,w);const S=(0,i.P_)(e.agentIdentifier),R=[w.beacon,w.errorBeacon];v||(S.proxy.assets&& (m(S.proxy.assets),R.push(S.proxy.assets)),S.proxy.beacon&&R.push(S.proxy.beacon),p(),(0,h.EZ)(\ ``` ```javascript activatedFeatures\ ``` ```javascript ,g.T)),E.denyList=[...S.ajax.deny_list||[],...S.ajax.block_internal?R:[]],(0,i.sU)(e.agentIdentifier,E),void 0===e.api&& (e.api=function(e,t){t||(0,c.R)(e,\ ``` ```javascript api\ ``` ```javascript \ ``` ```javascript );const h={};var p=a.ee.get(e),g=p.get(\ ``` ```javascript tracer\ ``` ```javascript \ ``` ```javascript ,m=\ ``` ```javascript api-\ ``` ```javascript ,v=m+\ ``` ```javascript ixn-\ ``` ```javascript \ ``` ```javascript );function b(t,r,n,o){const a=(0,i.C5)(e);return null===r?delete a.jsAttributes[t]:(0,i.CX)(e,{...a,jsAttributes:{...a.jsAttributes,[t]:r}}),w(m,n,!0,o||null===r?\ ``` ```javascript session\ ``` ```javascript \ ``` ```javascript )(t,r)}function y(){}[\ ``` ```javascript setErrorHandler\ ``` ```javascript ,\ ``` ```javascript finished\ ``` ```javascript ,\ ``` ```javascript addToTrace\ ``` ```javascript ,\ ``` ```javascript addRelease\ ``` ```javascript \ ``` ```javascript ].forEach((e=\u003e{h[e]=w(m,e,!0,\ ``` ```javascript api\ ``` ```javascript \ ``` ```javascript )}),h.addPageAction=w(m,\ ``` ```javascript addPageAction\ ``` ```javascript \ ``` ```javascript ,!0,n.D.pageAction),h.setCurrentRouteName=w(m,\ ``` ```javascript routeName\ ``` ```javascript \ ``` ```javascript ,!0,n.D.spa),h.setPageViewName=function(t,r){if(\ ``` ```javascript string\ ``` ```javascript ==typeof t)return/\ ``` ```javascript !\ ``` ```javascript !=t.charAt(0)\u0026\u0026(t=\ ``` ```javascript /\ ``` ```javascript \ ``` ```javascript +t),(0,i.OP)(e).customTransaction=(r||\ ``` ```javascript http://custom.transaction\ ``` ```javascript \ ``` ```javascript +t,w(m,\ ``` ```javascript setPageViewName\ ``` ```javascript \ ``` ```javascript ,!0)},h.setCustomAttribute=function(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(\ ``` ```javascript string\ ``` ```javascript ==typeof e){if(\[\ ``` ```javascript string\ ``` ```javascript ,\ ``` ```javascript number\ ``` ```javascript ,\ ``` ```javascript boolean\ ``` ```javascript \ ``` ```javascript \]\.includes(typeof t)||null===t)return b(e,t,\ ``` ```javascript setCustomAttribute\ ``` ```javascript \ ``` ```javascript ,r);(0,l.Z)(\ ``` ```javascript Failed to execute setCustomAttribute.\\nNon-null value must be a string, number or boolean type, but a type of \u003c\" ``` ```javascript "+typeof t+\ ``` ```javascript \ ``` ```javascript was provided.\ ``` ```javascript \ ``` ```javascript )}else(0,l.Z)(\ ``` ```javascript Failed to execute setCustomAttribute.\\nName must be a string type, but a type of \u003c\" ``` ```javascript "+typeof e+\ ``` ```javascript \ ``` ```javascript was provided.\ ``` ```javascript \ ``` ```javascript )},h.setUserId=function(e){if(\ ``` ```javascript string\ ``` ```javascript ==typeof e||null===e)return b(\ ``` ```javascript enduser.id\ ``` ```javascript \ ``` ```javascript ,e,\ ``` ```javascript setUserId\ ``` ```javascript \ ``` ```javascript ,!0);(0,l.Z)(\ ``` ```javascript Failed to execute setUserId.\\nNon-null value must be a string type, but a type of \u003c\" ``` ```javascript "+typeof e+\ ``` ```javascript \ ``` ```javascript was provided.\ ``` ```javascript \ ``` ```javascript )},h.setApplicationVersion=function(e){if(\ ``` ```javascript string\ ``` ```javascript ==typeof e||null===e)return b(\ ``` ```javascript application.version\ ``` ```javascript \ ``` ```javascript ,e,\ ``` ```javascript setApplicationVersion\ ``` ```javascript \ ``` ```javascript ,!1);(0,l.Z)(\ ``` ```javascript Failed to execute setApplicationVersion. Expected \u003cString | null\u003e, but got \u003c\" ``` ```javascript "+typeof e+\ ``` ```javascript \ ``` ```javascript \u003e.\ ``` ```javascript \ ``` ```javascript )},h.start=e=\u003e{try{const t=e?\ ``` ```javascript defined\ ``` ```javascript \ ``` ```javascript :\ ``` ```javascript undefined\ ``` ```javascript \ ``` ```javascript \ ``` ```javascript ;(0,o.p)(f.xS,[\ ``` ```javascript API/start/\" ``` ```javascript "+t+\ ``` ```javascript /called\" ``` ```javascript ],void 0,n.D.metrics,p);const r=Object.values(n.D);if(void 0===e)e=r;else{if((e=Array.isArray(e)&&e.length?e:[e]).some((e=\u003e!r.includes(e))))return(0,l.Z)(\ ``` ```javascript Invalid feature name supplied. Acceptable feature names are: \" ``` ```javascript "+r));e.includes(n.D.pageViewEvent)||e.push(n.D.pageViewEvent)}e.forEach((e=\u003e{p.emit(\ ``` ```javascript "+e+\ ``` ```javascript -opt-in\" ``` ```javascript )}))catch(e){(0,l.Z)(\ ``` ```javascript An unexpected issue occurred\" ``` ```javascript ,e)}},h.recordReplay=function(){(0,o.p)(f.xS,[\ ``` ```javascript API/recordReplay/called\ ``` ```javascript ],void 0,n.D.metrics,p),(0,o.p)(\ ``` ```javascript rec ``` -------------------------------- ### Get Influencer Feed Items Source: https://github.com/microlinkhq/metascraper/blob/master/packages/metascraper/test/integration/linkedin-pulse/input.html Constructs a GET request URL for fetching influencer feed items. Includes parameters for pagination ('start', 'count'), 'fullPageKey', and 'contextId'. ```javascript _nS('com.linkedin.news.controllers.FsController'); _root.com.linkedin.news.controllers.FsController.influencers = function (start, count, fullPageKey, contextId) { return _wA({ method: "GET", url: "/pulse/" + "fs/influencers" + _qS([ (start == null ? null : (function (k, v) { return encodeURIComponent(k) + '=' + encodeURIComponent(v) })("start", start)), (count == null ? null : (function (k, v) { return encodeURIComponent(k) + '=' + encodeURIComponent(v) })("count", count)), (fullPageKey == null ? null : (function (k, v) { return v != null ? (function (k, v) { return encodeURIComponent(k) + '=' + encodeURIComponent(v) })(k, v) : '' })("fullPageKey", fullPageKey)), (c ``` -------------------------------- ### Configuration Object Example Source: https://github.com/microlinkhq/metascraper/blob/master/packages/metascraper/test/integration/instagram/input.html An example of a configuration object containing various settings for application features, including performance metrics, UI elements, and routing. ```javascript var config = { fig: { "bbs": 100, "ctw": null, "dbs": 100, "fd": 60, "hbc": { "hbbi": 30, "hbcbc": 2, "hbi": 60, "hbv": "a8f002be11a021174fcb54b927b226a9", "hbvbc": 0 }, "i": 60, "rt": 262144, "sbs": 1, "sc": { "c": [ [30000, 838801], [30001, 838801], [30002, 838801], [30003, 838801], [30004, 838801], [30005, 838801], [30006, 573585], [30007, 838801], [30008, 838801], [30009, 838801], [30010, 838801], [30012, 838801], [30013, 838801], [30015, 806033], [30018, 806033], [30019, 806033], [30040, 806033], [30093, 806033], [30094, 806033], [30095, 806033], [30100, 541591], [30101, 541591], [30102, 541591], [30103, 541591], [30104, 541591], [30106, 806039], [30107, 806039], [38000, 541427], [38001, 806643] ], "t": 1618437631 }, "sid": -1 }, "consent_dialog_config": { "is_user_linked_to_fb": false, "should_show_consent_dialog": true, "should_use_winning_qe": null }, "privacy_flow_trigger": null, "www_routing_config": { "COMMENT": "frontend_gk is only used by clients, if you change a frontend_gk you must also make a diff to proxygen", "routes": [{"path": "/?", "destination": "WWW", "frontend_gk": "ig_web_to_www_feed" }, {"path": "/explore/people/?", "destination": "WWW", "frontend_gk": "ig_web_to_www_explore_people_full_page" }, {"path": "/direct/inbox/?", "destination": "WWW", "frontend_gk": "ig_web_to_www_direct" }] }, "rollout_hash": "50dffb5e87a1", "bundle_variant": "es6", "frontend_env": "prod" }; ``` -------------------------------- ### Initialize Metascraper Source: https://github.com/microlinkhq/metascraper/blob/master/packages/metascraper/test/integration/nytimes/input/article.html Initialize Metascraper with a URL to start extracting metadata. Ensure you have the necessary modules installed. ```javascript const metascraper = require('metascraper') const url = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ' async () => { const metadata = await metascraper({ url }) console.log(metadata) } ``` -------------------------------- ### Get Alternate Language from Pathname Source: https://github.com/microlinkhq/metascraper/blob/master/packages/metascraper/test/integration/nytimes/input/opinion.html Extracts the alternate language code (e.g., 'es') from the URL pathname if it starts with '/es/'. ```javascript getAltLangFromPathname: function (t = "") { return 0 === t.indexOf("/es/") ? "es" : "" } ``` -------------------------------- ### Initialize Agent Source: https://github.com/microlinkhq/metascraper/blob/master/packages/metascraper/test/integration/san-francisco-chronicle/input.html Initializes the agent with provided configuration. Use this to set up the agent for tracking and reporting. ```javascript b(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},b=arguments.length>2?arguments[2]:void 0,y=arguments.length>3?arguments[3]:void 0,{init:A,info:w,loader_config:x,runtime:E={loaderType:b},exposed:_=!0}=t;const T=(0,h.gG)();w||(A=T.init,w=T.info,x=T.loader_config),(0,i.Dg)(e.agentIdentifier,A||{}),(0,i.GE)(e.agentIdentifier,x||{}),w.jsAttributes??={},d.v6&&(w.jsAttributes.isWorker=!0),(0,i.CX)(e.agentIdentifier,w);const S=(0,i.P_)(e.agentIdentifier),R=[w.beacon,w.errorBeacon];v||(S.proxy.assets&&(m(S.proxy.assets),R.push(S.proxy.assets)),S.proxy.beacon&&R.push(S.proxy.beacon),p(),(0,h.EZ)( ``` ```javascript activatedFeatures",g.T)),E.denyList=[...S.ajax.deny_list||[],...S.ajax.block_internal?R:[]],(0,i.sU)(e.agentIdentifier,E),void 0===e.api&&(e.api=function(e,t){t||(0,c.R)(e,"api");const h={};var p=a.ee.get(e),g=p.get("tracer"),m="api-",v=m+"ixn-";function b(t,r,n,o){const a=(0,i.C5)(e);return null===r?delete a.jsAttributes[t]:(0,i.CX)(e,{...a,jsAttributes:{...a.jsAttributes,[t]:r}}),w(m,n,!0,o||null===r?"session":void 0)(t,r)}function y(){}"["setErrorHandler","finished","addToTrace","addRelease"].forEach((e=>{h[e]=w(m,e,!0,"api")})),h.addPageAction=w(m,"addPageAction",!0,n.D.pageAction),h.setCurrentRouteName=w(m,"routeName",!0,n.D.spa),h.setPageView ``` -------------------------------- ### Get Metadata with URL Validation Source: https://github.com/microlinkhq/metascraper/blob/master/packages/metascraper-readability/benchmark/fixture.html Metascraper includes built-in URL validation. This example shows how it handles invalid URLs. ```javascript const metascraper = require('metascraper') const url = 'invalid-url' const html = '' try { await metascraper({ html, url }) } catch (error) { console.error(error.message) // 'Invalid URL' } ``` -------------------------------- ### Initialization of Core Services Source: https://github.com/microlinkhq/metascraper/blob/master/packages/metascraper-audio/test/fixtures/providers/podcasts.google.com.html Initializes core services and singletons like `Pc`, `oc`, `Lc`, and `gc`. Sets up the application's foundational components. ```javascript _.Uc = new Yc; var Nc, Oc, Mc; _.G(_.Uc, mc, 3) || new mc; _.Vc() || new fc; _.jc = new oc; Nc = _.Vc() || new fc; Oc = _.Wc() || new _.gc; Mc = _.G(_.Uc, Lc, 4) || new Lc; new Pc; _.A("gbar._DumpException", function (a) { _.jc ? _.jc.log(a) : console.error(a) }); ``` -------------------------------- ### Initialize RXVM Source: https://github.com/microlinkhq/metascraper/blob/master/packages/metascraper-amazon/test/fixtures/amazon-com/ansi-url.html Initializes the RXVM with provided code and data. This function is the entry point for executing the virtual machine. ```javascript !function(n){for(var t="undefined"==typeof window?n:window,o=0,n="addEventListener",f="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"..split("),u=\[\],i=t.rx||"",r=i.c||"",e=r.rxp||"/rd/uedata",c=r.fi||5e3,a={},d={},w=\[\] ,v=0,x=0;x<64;x++)u[f[x]]=x;function h(n,i){return function(){try{return n.apply(this,arguments)}catch(n){l(n.message||n,n)}}}function l(n,i){n=(""+(n||"")).substring(0,100),w.push(o),w.push(n.length);for(var t=0;tTest', url: 'https://example.com' }) console.log(metadata) ``` -------------------------------- ### Initialize BuyItAgain Side Panel with $Nav Source: https://github.com/microlinkhq/metascraper/blob/master/packages/metascraper-amazon/test/fixtures/amazon-co-uk/product-url.html Initializes the BuyItAgain side panel functionality using the $Nav framework. It handles data fetching, rendering, and side panel events. Requires $Nav, data, flyout.yourAccount, sidepanel.csYourAccount, and config modules. ```javascript var ocInitTimestamp = 1704578636; (function ($Nav) { "use strict"; if (typeof $Nav === 'undefined' || $Nav === null || typeof $Nav.when !== 'function') { return; } $Nav.when('$', 'data', 'flyout.yourAccount', 'sidepanel.csYourAccount', 'config') .run("BuyitAgain-YourAccount-SidePanel", function ($, data, yaFlyout, csYourAccount, config) { if (config.disableBuyItAgain) { return; } var render = function (data) { if (data.dramResult) { var widgetHtml = data.dramResult; navbar.sidePanel({ flyoutName: 'yourAccount', data: {html: widgetHtml} }); } }; var renderBuyItAgain = function (biaData) { if (csYourAccount) { csYourAccount.register(render, biaData); } else { render(biaData); } }; var truncateAndRestructureYaFlyout = function() { if (window.P) { P.when('A', 'a-truncate').execute(function(A, truncate) { var truncateElements = A.$('.a-truncate'); A.each(truncateElements, function(element) { truncate.get(element).update(); }); var recommendationsWidget = document.getElementById('bia-hcb-widget'); if (recommendationsWidget) { var navFlyout = recommendationsWidget.parentElement; var navFlyoutPaddingBottom = parseInt(window.getComputedStyle(navFlyout).getPropertyValue('padding-bottom')); var navFlyoutContentHeight = navFlyout.clientHeight - navFlyoutPaddingBottom; while (recommendationsWidget.offsetHeight > navFlyoutContentHeight && recommendationsWidget.offsetHeight > 0){ var recommendations = recommendationsWidget.querySelectorAll('.biaNavFlyoutFaceout'); if (recommendations.length <= 1) { break; } var lastRecommendation = recommendations[recommendations.length - 1]; lastRecommendation.parentElement.removeChild(lastRecommendation); } } }); } }; yaFlyout.sidePanel.onData(truncateAndRestructureYaFlyout); yaFlyout.onShow(truncateAndRestructureYaFlyout); yaFlyout.onRender(function() { $.ajax({ url: '/gp/bia/external/bia-hcb-ajax-handler.html', data: {"biaHcbRid":"GEX17B1FK08P97V6F3XF"}, dataType: 'json', timeout: 4*1000, success: renderBuyItAgain, error: function (jqXHR, textStatus, errorThrown) { } }); }); }); })(window.$Nav); ``` -------------------------------- ### Get Metadata with `rules`, `plugins`, and `options` Source: https://github.com/microlinkhq/metascraper/blob/master/packages/metascraper-readability/benchmark/fixture.html A comprehensive example combining custom rules, external plugins, and general options for maximum flexibility. ```javascript const metascraper = require('metascraper') const myPlugin = require('metascraper-my-plugin') const rules = { customTitle: [metascraper.rule.title()], pluginField: [myPlugin.rule.someRule()] } const options = { timeout: 20000, plugins: [myPlugin] } const metadata = await metascraper({ html, url, rules, ...options }) console.log(metadata) ``` -------------------------------- ### Handle Voice Search Button Click Source: https://github.com/microlinkhq/metascraper/blob/master/packages/metascraper/test/integration/yahoo-news/input.html Starts speech recognition when the voice search button is clicked. Manages the permission guide and sends a beacon event. ```javascript a.voiceButton.onclick = function() { a.recognition.start(), a.permissionGuideTimer && e.clearTimeout(a.permissionGuideTimer), a.permissionGuideTimer = e.setTimeout((function() { a.isRecognitionStart || a.showPermissionGuide(a) }), 300), t.addEventListener("keydown", a.onEscKeyDown), a.sendBeacon("clk", "voicesearch") } ``` -------------------------------- ### Start Session Recording Source: https://github.com/microlinkhq/metascraper/blob/master/packages/metascraper/test/integration/atlasobscura/input.html Asynchronously starts the session recording process. It dynamically imports necessary modules and initializes the recorder. ```javascript async #s(e){if(!this.#c){this.#c=!0;try{const{Recorder:t}=await Promise.all([i.e(478),i.e(249)]).then(i.bind(i,8589));this.recorder??=new t({...this,mode:this.#n,agentRef:this.#i,trigger:e,timeKeeper:this.#i.runtime.timeKeeper}),this.recorder.startRecording(),this.abortHandler=this.recorder.stopRecording}catch(e){this.parent.ee.emit("internal-error",[e])}}this.importAggregator(this.#i,(()=>i.e(478).then(i.bind(i,6167))),{recorder:this.recorder,errorNoticed:this.errorNoticed})}} ``` -------------------------------- ### Get URL Pathname Source: https://github.com/microlinkhq/metascraper/blob/master/packages/metascraper/test/integration/jewish-business-news/input.html Extracts the pathname from a URL, optionally removing the site URL prefix. It ensures the pathname starts with a '/' and adds a trailing slash if configured. ```javascript {key:"_getPathname",value:function(e,t){var n=t?e.substring(this.config.siteUrl.length):e;return n.startsWith("/")|| (n="/"+n),this._shouldAddTrailingSlash(n)?n+"/":n}} ``` -------------------------------- ### Initialize and manage UI components Source: https://github.com/microlinkhq/metascraper/blob/master/packages/metascraper-audio/test/fixtures/providers/podcasts.google.com.html Initializes UI components like menus and back buttons, sets up event listeners for keyboard and touch interactions, and handles window resize events. Use this for setting up complex UI elements with dynamic behavior. ```javascript ei = class extends _.sh { constructor(a, b, c, d, e) { const f = a.get("menu"); super(f); this.i = b; this.X = f; this.J = a; this.qa = a.get("back"); this.F = _.Q("gb_Hc"); this.L = c; this.o = _.Q("gb_Sc", this.i); this.M = new Kh(this.o); this.C = _.Q("gb_Tc", this.o); this.H = _.Q("gb_Uc", this.o); this.O = {}; this.P = []; this.T = d || !1; this.W = e || !1; this.j = new _.cg(this); Yh(this); a = this.o.getElementsByClassName("gb_Vc"); for (b = 0; b < a.length; b++) this.s(new Uh(this, a[b])) } N() { super.N(); Zh(this) } G() { return this.o } ta() { return _.Q("gb_Zd", this.i) } Ra() { $h(this); return ai(this, this.C) } Pa() { $h(this); return ai(this, this.H) } Aa(a) { _.Y(this.i, "gb_Qc", 1 == a); this.dispatchEvent("msc") } getStyle() { return di(this) ? 0 : 1 } kb(a) { this.F || (this.F = _.Q("gb_Hc")); this.F && a && _.Td(this.F, a) } isVisible(a) { return (a = this.J.get(a)) ? !_.R(a, "gb_p") : !1 } open(a) { this.L || (a && _.X(this.i, "transition", "none"), this.dispatchEvent("beforeshow"), _.T(this.i, "gb_Ca"), _.Wd(this.D(), "expanded", !0), Mh(this.o), Hh(this.M), this.dispatchEvent("open"), this.j.o(document.body, Wh, this.S, !0, this), this.j.listen(document.body, "focusin", this.R), a && _.$f(function() { _.X(this.i, "transition", "") }, 0, this)) } hb(a) { this.L && _.Wd(this.D(), "expanded", a) } close(a) { this.L || (a && _.X(this.i, "transition", "none"), _.ee(this.i, "gb_Ca"), _.Wd(this.D(), "expanded", !1), document.activeElement == this.D() && this.D().blur(), Jh(this.M), this.dispatchEvent("close"), Zh(this), a && _.$f(function() { _.X(this.i, "transition", "") }, 0, this)) } v() { return _.R(this.i, "gb_Ca") } U() { const a = window.visualViewport ? window.visualViewport.height : window.innerHeight; a && _.X(this.i, "height", `calc(${a}px - 100%) `) } va() { this.dispatchEvent("mbc"); if (!this.L) { if (this.v()) { this.close(); var a = !0 } else this.open(), a = !1; a && this.D().focus() } } Za(a) { 9 === a.keyCode && this.v() && (a = this.M, _.Y(a.i, "gb_N", !0), Ih(a)) } wa(a) { a: { if (36 == a.keyCode || 35 == a.keyCode) { var b = _.ph(this.i); if (0 < b.length) { var c = b[b.length - 1]; 36 == a.keyCode && (c = !di(this) && 1 < b.length ? b[1] : b[0]); c.focus(); a.preventDefault(); break a } } 27 != a.keyCode || this.T && !di(this) || (this.close(), null != this.X && this.X.focus()) } 9 === a.keyCode && this.v() && di(this) && (b = a.target, c = _.ph(this.i), 0 < c.length && (b == c[0] && a.shiftKey ? (c[c.length - 1].focus(), a.preventDefault()) : b != c[c.length - 1] || a.shiftKey || (c[0].focus(), a.preventDefault()))) } ab(a) { if (a.target instanceof Node) { a: { a = a.target; for (var b = this.o; a && a !== b;) { var c = a.id; if (c in this.O) { a = this.O[c]; break a } a = a.parentNode } a = null } if (a) { b = a.j(); c = this.P.length; for (let d = 0; d < c; ++d) a = this.P[d], a.i.call(a.j, b); this.T && !di(this) || this.close() } } } S(a) { this.v() && a.target instanceof Node && !(!di(this) || this.W && _.Ng(a.target, Vh)) && ("keydown" == a.type ? 27 == a.keyCode && (a.preventDefault(), a.stopPropagation(), this.close(), this.D().focus()) : _.Pg(a.target, "gb_W") || _.Pg(a.target, "gb_Ec") || _.Vf(this.i, a.target) || ("touchstart" == a.type && (a.preventDefault(), a.stopPropagation()), this.close())) } R() { this.v() && (!di(this) || "IFRAME" != document.activeElement.tagName && (this.W & ``` -------------------------------- ### Initialize YouTube CSI (Client-Side Instrumentation) Source: https://github.com/microlinkhq/metascraper/blob/master/packages/metascraper-youtube/test/fixtures/youtube-video-old.html Initializes the YouTube Client-Side Instrumentation (CSI) object, providing methods to record performance ticks, store information, and log GEL (Google Engagement Layer) events. It includes functions for getting current time and setting start times for measurements. ```javascript var ytcsi={gt:function(n){n=(n||"")+"data_";return ytcsi[n]||(ytcsi[n]={tick:{},info:{},gel:{preLoggedGelInfos:[]}})},now:window.performance&&window.performance.timing&&window.performance.now&&window.performance.timing.navigationStart?function(){return window.performance.timing.navigationStart+window.performance.now()}:function(){return(new Date).getTime()},tick:function(l,t,n){var ticks=ytcsi.gt(n).tick;var v=t||ytcsi.now();if(ticks[l]){ticks["_"+l]=ticks["_"+l]||[ticks[l]];ticks["_"+l].push(v)}ticks[l]= v},info:function(k,v,n){ytcsi.gt(n).info[k]=v},infoGel:function(p,n){ytcsi.gt(n).gel.preLoggedGelInfos.push(p)},setStart:function(t, ``` -------------------------------- ### Initialize Metascraper with Options Source: https://github.com/microlinkhq/metascraper/blob/master/packages/metascraper/test/integration/yahoo-news/input.html Demonstrates how to initialize Metascraper with custom options for handling metadata extraction. ```javascript const metascraper = require('metascraper') const html = require('fs').readFileSync('index.html') const options = { html: html, url: 'https://example.com' } metascraper(options).then(metadata => console.log(metadata)) ``` -------------------------------- ### Start Agent Source: https://github.com/microlinkhq/metascraper/blob/master/packages/metascraper/test/integration/san-francisco-chronicle/input.html Starts the agent, optionally with a list of features to enable. If no features are provided, all available features are enabled. Validates provided feature names against available ones. ```javascript h.start=e=>{try{const t=e?"defined":"undefined";(0,o.p)(f.xS,["API/start/"..concat(t,"/called")],void 0,n.D.metrics,p);const r=Object.values(n.D);if(void 0===e)e=r;else{if((e=Array.isArray(e)&&e.length?e:["defined"]).some((e=>!r.includes(e))))return(0,l.Z)("Invalid feature name supplied. Acceptable feature names are: ".concat(r));e.includes(n.D.pageViewEvent)||e.push(n.D.pageViewEvent)}e.forEach((e=>{p.emit("".concat(e,"-opt-in"))}))}catch(e){(0,l.Z)("An unexpected issue occurred",e)}}, ``` -------------------------------- ### Start Duration Vital Source: https://github.com/microlinkhq/metascraper/blob/master/packages/metascraper/test/integration/vimeo/input.html Starts tracking a duration vital. Records the start time and context for later measurement. ```javascript function Ne(t,e,n){var r=t.vitalsByName,i=t.vitalsByReference;void 0===n&&(n={});var o={name:e,startClocks:ne(),context:n.context,description:n.description},a={__dd_vital_reference:!0};return r.set(e,o),i.set(a,o),a} ``` -------------------------------- ### Run RocketLazyLoadScripts Source: https://github.com/microlinkhq/metascraper/blob/master/packages/metascraper/test/integration/eweek/input.html Initializes and runs the RocketLazyLoadScripts by creating an instance and adding user interaction listeners. This is the main entry point for the script's functionality. ```javascript static run(){let e=new RocketLazyLoadScripts;e._addUserInteractionListener(e)}}RocketLazyLoadScripts.run(); ``` -------------------------------- ### Start Agent Features Source: https://github.com/microlinkhq/metascraper/blob/master/packages/metascraper/test/integration/techmonitor/input.html Starts specified features for the agent. If no features are provided, all available features are started. Accepts a feature name string or an array of feature names. Ensures 'pageViewEvent' is included if other features are started. ```javascript h.start=e=>{try{const t=e?"defined":"undefined";(0,o.p)(f.xS,["API/start/".concat(t,"/called")],void 0,n.D.metrics,p);const r=Object.values(n.D);if(void 0===e)e=r;else{if((e=Array.isArray(e)&&e.length?e:["object"==typeof e?e:String(e)]).some((e=>!r.includes(e))))return(0,l.Z)("Invalid feature name supplied. Acceptable feature names are: ".concat(r));e.includes(n.D.pageViewEvent)||e.push(n.D.pageViewEvent)}e.forEach((e=>{p.emit("".concat(e,"-opt-in"))}))}catch(e){(0,l.Z)("An unexpected issue occurred",e)}} ```