Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
//seriously fuck CORS it works too well// Function to search Arquivo.pt and get results countfunctionsearchArquivoAndGetResults(){// Create a hidden iframe to load the search resultsconstiframe=document.createElement('iframe');iframe.style.display='none';iframe.style.width='0';iframe.style.height='0';document.body.appendChild(iframe);// Build the search URLconstsearchQuery='example.com';constsearchUrl=`https://arquivo.pt/page/search?q=${encodeURIComponent(searchQuery)}&l=pt&from=19910806&to=20250523`;returnnewPromise((resolve,reject)=>{// Set up load handleriframe.onload=function(){try{// Wait a bit for dynamic content to loadsetTimeout(()=>{try{constiframeDoc=iframe.contentDocument||iframe.contentWindow.document;// Look for the results elementconstresultsElement=iframeDoc.querySelector('#estimated-results-value');if(resultsElement){constresultsText=resultsElement.textContent;// Extract number from text like "Cerca de 1.410 resultados desde 1991 até 2025"constnumberMatch=resultsText.match(/[\d.,]+/);constresultsCount=numberMatch?numberMatch[0].replace(/\./g,'').replace(/,/g,''):'0';// Clean updocument.body.removeChild(iframe);// Return resultsresolve({count:parseInt(resultsCount),fullText:resultsText,success:true});}else{// If no results element found, try again after longer waitsetTimeout(()=>{constresultsElement2=iframeDoc.querySelector('#estimated-results-value');if(resultsElement2){constresultsText=resultsElement2.textContent;constnumberMatch=resultsText.match(/[\d.,]+/);constresultsCount=numberMatch?numberMatch[0].replace(/\./g,'').replace(/,/g,''):'0';document.body.removeChild(iframe);resolve({count:parseInt(resultsCount),fullText:resultsText,success:true});}else{document.body.removeChild(iframe);reject(newError('Results element not found after waiting'));}},3000);}}catch(error){document.body.removeChild(iframe);reject(newError('Cannot access iframe content due to CORS: '+error.message));}},2000);// Wait 2 seconds for page to load}catch(error){document.body.removeChild(iframe);reject(error);}};iframe.onerror=function(){document.body.removeChild(iframe);reject(newError('Failed to load Arquivo.pt page'));};// Load the search URLiframe.src=searchUrl;// Timeout after 15 secondssetTimeout(()=>{if(document.body.contains(iframe)){document.body.removeChild(iframe);reject(newError('Timeout waiting for results'));}},15000);});}// Function to add button to watchlist (call this when page loads)functionaddArquivoButton(){// Only add if we're on the watchlist pageif(!window.___location.href.includes('Special:Watchlist')){return;}// Check if button already existsif(document.getElementById('arquivo-search-btn')){return;}// Create buttonconstbutton=document.createElement('button');button.id='arquivo-search-btn';button.innerHTML='🔍 Search Arquivo.pt';button.style.cssText=` margin: 5px; padding: 8px 12px; background: #0645ad; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 12px; `;// Add click handlerbutton.addEventListener('click',asyncfunction(){button.disabled=true;button.innerHTML='⏳ Searching...';try{constresults=awaitsearchArquivoAndGetResults();alert(`Found ${results.count} results on Arquivo.pt!\n\nFull text: "${results.fullText}"`);}catch(error){alert(`Error searching Arquivo.pt: ${error.message}`);console.error('Arquivo.pt search error:',error);}finally{button.disabled=false;button.innerHTML='🔍 Search Arquivo.pt';}});// Add button to page (you may need to adjust the selector)consttargetElement=document.querySelector('#mw-content-text')||document.querySelector('.mw-body-content')||document.body;if(targetElement){targetElement.insertBefore(button,targetElement.firstChild);}}// Auto-add button when page loadsif(document.readyState==='loading'){document.addEventListener('DOMContentLoaded',addArquivoButton);}else{addArquivoButton();}