UNPKG

@linked-claims/trustclip

Version:

Bookmarklet tools for extracting claims from web pages and linking them into a web of trust

220 lines (206 loc) 7.5 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.ts var index_exports = {}; __export(index_exports, { ClaimExtractionBookmarklet: () => ClaimExtractionBookmarklet, DynamicLoaderBookmarklet: () => DynamicLoaderBookmarklet, LinkedInBookmarklet: () => LinkedInBookmarklet }); module.exports = __toCommonJS(index_exports); // src/bookmarklets/linkedin.ts var LinkedInBookmarklet = class { constructor(options) { this.apiEndpoint = options.apiEndpoint; this.tokenKey = options.tokenKey || "linkedin_verification_token"; } getBookmarkletCode(minified = true) { const code = `(function(){ // Only run on LinkedIn if (!window.location.hostname.includes('linkedin.com')) { alert('This verification tool only works on LinkedIn pages'); return; } // Extract member since from the page const pageText = document.body.innerText; const memberSinceMatch = pageText.match(/Member since ([A-Za-z]* )?(\\d{4})/i); if (!memberSinceMatch) { alert('Could not find "Member since" on this page. Make sure you are on a LinkedIn profile page.'); return; } const fullText = memberSinceMatch[0]; const monthPart = memberSinceMatch[1] ? memberSinceMatch[1].trim() : ''; const yearPart = memberSinceMatch[2]; // Get verification token from sessionStorage const verificationToken = sessionStorage.getItem('${this.tokenKey}'); if (!verificationToken) { alert('Please complete LinkedIn verification on TalentStamp first'); return; } // Extract profile ID from URL const pathParts = window.location.pathname.split('/'); const profileId = pathParts[pathParts.length - 1] || pathParts[pathParts.length - 2]; // Confirm with user const confirmSend = confirm('Found: "' + fullText + '"\\n\\nSend this verification to TalentStamp?'); if (!confirmSend) { return; } // Send to backend fetch('${this.apiEndpoint}', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-Verification-Token': verificationToken }, body: JSON.stringify({ memberSince: fullText, year: parseInt(yearPart), month: monthPart, profileUrl: window.location.href, profileId: profileId, timestamp: new Date().toISOString() }) }) .then(response => response.json()) .then(data => { if (data.success) { alert('\u2705 LinkedIn account age verified successfully!'); sessionStorage.removeItem('${this.tokenKey}'); } else { alert('Failed to verify: ' + (data.error || 'Unknown error')); } }) .catch(error => { console.error('Error:', error); alert('Failed to send verification. Please try again.'); }); })();`; if (minified) { return code.replace(/\/\/.*$/gm, "").replace(/\s+/g, " ").replace(/\s*([{}();,:])\s*/g, "$1").trim(); } return code; } getBookmarkletURI() { return `javascript:${this.getBookmarkletCode(true)}`; } }; // src/bookmarklets/claim-extraction.ts var BaseBookmarklet = class { constructor(apiEndpoint) { this.apiEndpoint = apiEndpoint; } getBookmarkletURI() { return `javascript:${this.getBookmarkletCode(true)}`; } minify(code) { return code.replace(/\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\/|/g, "").replace(/\s+/g, " ").replace(/\s*([{}();,:])\s*/g, "$1").trim(); } }; var ClaimExtractionBookmarklet = class extends BaseBookmarklet { constructor(options) { super(options.apiEndpoint); this.enableOnSelect = options.enableOnSelect ?? false; } getBookmarkletCode(minified = true) { const code = `(function(){ function getSelectedContent(){ var selection=window.getSelection(); var container=document.createElement("div"); for(var i=0;i<selection.rangeCount;i++){ var range=selection.getRangeAt(i); var fragment=range.cloneContents(); container.appendChild(fragment); } var links=container.getElementsByTagName("a"); for(var i=links.length-1;i>=0;i--){ var link=links[i]; var text=link.textContent; var href=link.getAttribute("href"); if(href&&href!==text){ link.replaceWith(text+" ("+href+")"); } } return container.innerText.trim().replace(/\\s+/g," "); } ${this.enableOnSelect ? ` document.addEventListener("mouseup",function(){ var currentPageUrl=window.location.href; var selectedText=getSelectedContent(); if(selectedText.length>0){ var confirmSend=confirm("Selected text: \\""+selectedText+"\\". Do you want to send this text?"); if(confirmSend){ fetch("${this.apiEndpoint}",{ method:"POST", headers:{"Content-Type":"application/json"}, body:JSON.stringify({text:selectedText,source_url:currentPageUrl}) }) .then(response=>response.json()) .then(data=>{alert("Text sent successfully!");}) .catch(error=>{console.log("Error:",error);alert("Failed to send text.");}); } } }); ` : ` var currentPageUrl=window.location.href; var selectedText=getSelectedContent(); if(selectedText.length===0){ alert("Please select some text first!"); return; } var confirmSend=confirm("Selected text: \\""+selectedText+"\\". Do you want to send this text?"); if(confirmSend){ fetch("${this.apiEndpoint}",{ method:"POST", headers:{"Content-Type":"application/json"}, body:JSON.stringify({text:selectedText,source_url:currentPageUrl}) }) .then(response=>response.json()) .then(data=>{alert("Text sent successfully!");}) .catch(error=>{console.log("Error:",error);alert("Failed to send text.");}); } `} })();`; return minified ? this.minify(code) : code; } }; var DynamicLoaderBookmarklet = class extends BaseBookmarklet { getBookmarkletCode(minified = true) { const code = `(function(){ if(window._bookmarkletLoaded){ alert('LinkedClaims already active!'); return; } window._bookmarkletLoaded=true; const s=document.createElement('script'); s.src='${this.apiEndpoint}/bookmarklet.js?t='+new Date().getTime(); s.onerror=function(){ alert('Error loading LinkedClaims. Please try again.'); window._bookmarkletLoaded=false; }; document.body.appendChild(s); })();`; return minified ? this.minify(code) : code; } }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { ClaimExtractionBookmarklet, DynamicLoaderBookmarklet, LinkedInBookmarklet });