diff --git a/build-scripts/prep-browserext.js b/build-scripts/prep-browserext.js index d506318..0029ddf 100644 --- a/build-scripts/prep-browserext.js +++ b/build-scripts/prep-browserext.js @@ -3,18 +3,18 @@ const packageJson = require('../package.json'); const manifestJson = require('../browser-ext/manifest.json'); const browserExtSrcDir = `${__dirname}/../browser-ext/`; -const mainJs = `${__dirname}/../build/main.js`; -const buildDir = `${__dirname}/../build-browserext/`; +const buildDir = `${__dirname}/../build/`; +const browserBuildDir = `${__dirname}/../build-browserext/`; // Clean out build dir -fse.emptyDirSync(buildDir); +fse.emptyDirSync(browserBuildDir); // Copy all files from browser extension folder to build -fse.copySync(browserExtSrcDir, buildDir); +fse.copySync(browserExtSrcDir, browserBuildDir); // Copy version number over to manifest, and write it out to build dir manifestJson.version = packageJson.version; -fse.writeFileSync(`${buildDir}manifest.json`, JSON.stringify(manifestJson, null, 4)); +fse.writeFileSync(`${browserBuildDir}manifest.json`, JSON.stringify(manifestJson, null, 4)); // Copy main js file, after babel, over to build -fse.copyFileSync(mainJs, `${buildDir}main.js`); +fse.copySync(buildDir, browserBuildDir); diff --git a/src/main.js b/src/main.js index 39b4b49..b71469b 100644 --- a/src/main.js +++ b/src/main.js @@ -499,7 +499,7 @@ window.LinkedinToResumeJson = (() => { /** @type {ParseProfileSchemaResultSummary} */ const resultSummary = { profileObj, - pageUrl: _this.getUrlWithoutQuery(), + pageUrl: null, parseSuccess: false, sections: { basics: 'fail', @@ -732,7 +732,7 @@ window.LinkedinToResumeJson = (() => { resultSummary.sections.publications = publicationEntries.length ? 'success' : 'empty'; if (_this.debug) { - console.group('parseProfileSchemaJSON complete:'); + console.group(`parseProfileSchemaJSON complete: ${document.location.pathname}`); console.log({ db, _outputJson, @@ -743,6 +743,7 @@ window.LinkedinToResumeJson = (() => { _this.parseSuccess = true; resultSummary.parseSuccess = true; + resultSummary.pageUrl = _this.getUrlWithoutQuery(); } catch (e) { if (_this.debug) { console.group('Error parsing profile schema'); @@ -1164,7 +1165,6 @@ window.LinkedinToResumeJson = (() => { } // Get directly via API - // .... const fullProfileView = await this.voyagerFetch(_voyagerEndpoints.fullProfileView); // Try to use the same parser that I use for embedded const profileParserResult = await parseProfileSchemaJSON(this, fullProfileView); @@ -1374,7 +1374,7 @@ window.LinkedinToResumeJson = (() => { * Get the profile ID / User ID of the user by parsing URL first, then page. */ LinkedinToResumeJson.prototype.getProfileId = function getProfileId() { - let profileId; + let profileId = ''; const linkedProfileRegUrl = /linkedin.com\/[^\/]*\/([^\/]+)\/[^\/]*$/im; const linkedProfileRegApi = /voyager\/api\/.*\/profiles\/([^\/]+)\/.*/im; if (linkedProfileRegUrl.test(document.location.href)) { @@ -1387,12 +1387,8 @@ window.LinkedinToResumeJson = (() => { profileId = linkedProfileRegApi.exec(document.body.innerHTML)[1]; } - if (profileId) { - // In case username contains special characters - return decodeURI(profileId); - } - - return false; + // In case username contains special characters + return decodeURI(profileId); }; /** @@ -1458,6 +1454,8 @@ window.LinkedinToResumeJson = (() => { const profileDb = buildDbFromLiSchema(fullProfileView); const profileViewUrnPatt = /urn:li:fs_profileView:(.+)$/i; this.profileUrnId = profileDb.tableOfContents['entityUrn'].match(profileViewUrnPatt)[1]; + } else { + this.debugConsole.warn('Could not scrape profileUrnId from DOM, but fetch is disallowed. Might be using a stale ID!'); } return this.profileUrnId; @@ -1657,7 +1655,10 @@ window.LinkedinToResumeJson = (() => { */ LinkedinToResumeJson.prototype.formatVoyagerUrl = async function formatVoyagerUrl(fetchEndpoint) { // Macro support - let endpoint = fetchEndpoint.replace(/{profileId}/g, this.profileId); + let endpoint = fetchEndpoint; + if (endpoint.includes('{profileId}')) { + endpoint = fetchEndpoint.replace(/{profileId}/g, this.getProfileId()); + } if (endpoint.includes('{profileUrnId}')) { const profileUrnId = await this.getProfileUrnId(); endpoint = endpoint.replace(/{profileUrnId}/g, profileUrnId);