Skip to content

Added some surrogates #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/legacy/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,20 @@ Legacy.migrated.prefs = Object.assign(
"surrogate.stripe.sources": "js.stripe.com",
"surrogate.wp.sources": "!^.*\\/20\\d{2}\\/\\d{2}\\/\\d{2}\\/",
"surrogate.wp.replacement": "let s=document.createElement('style');s.textContent='.site{opacity: 1 !important}';document.documentElement.appendChild(s)",
"surrogate.oracle_downloads.sources": "!^https?://(?:www\\.)oracle\\.com/.+?/downloads/[^\\/]+?-downloads-.+$",
"surrogate.oracle_downloads.replacement" : "document.cookie = 'oraclelicense=accept-securebackup-cookie; domain=.oracle.com; path=/; expires=' +(new Date(Date.now() + 1800000)).toGMTString();",
"surrogate.microsoft_kb.sources" : "!https?://support\\.microsoft\\.com/(\\w{2}-\\w{2,3}/help|kb)/\\d+(/.+)?",
"surrogate.microsoft_kb.replacement" : "'use strict';let ce=document.createElement.bind(document);let r=/microsoft\\.support\\.prefetchedArticle\\s*=\\s*\\(\\s*function\\s*\\(\\s*\\)\\s*\\{\\s*return\\s+([^]+?)\\}\\)\\(\\);/m;let x=/'([a-z]{2}(?:-[a-z]{2})?\\/\\d+)'/g;let t;for(let w of document.getElementsByTagName('SCRIPT')){if(!w.src){let m=w.textContent.match(r);if(m){t=m[1].replace(x,'\"$1\"');break;}}}let j=JSON.parse(t),M=document.getElementById('mainContent');function A(a,b){a=new Date(a);var g=ce('time'),n=ce('p');n.textContent=b;g.a=a;g.textContent=a;n.appendChild(g);M.appendChild(n);}M.innerHTML='';for(let B in j){var d=j[B].details,h=ce('h1');document.head.title=h.textContent='KB'+d.id+' - '+d.heading;M.appendChild(h);A(d.createdOn,'created: ');A(d.publishedOn,'published: ');var s=ce('section');s.textContent=d.description;M.appendChild(s);for(var body of d.body){let S=ce('section'),J=ce('h3');J.textContent=body.title;S.appendChild(J);var P=ce('p');P.innerHTML=body.content;S.appendChild(P);M.appendChild(S)}var a=ce('a');a.textContent='Download JSON';a.download='KB'+d.id+'.json';a.href=URL.createObjectURL(new Blob([JSON.stringify(j,null,'\\t')],{type:'application/json'}));a.style.color='blue';M.appendChild(a);break;}",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this actually do? There's a lot of it for a simple surrogate.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parses data encoded into a JS object (by carving them with regexp, fixing quotes to make a valid JSON and then using JSON.parse, no actual code execution involved) and renderes them. Also adds a link to download them as JSON.

"surrogate.microsoft_VisualStudio_download.sources" : "!https://(www\\.)?visualstudio\\.com/thank-you-downloading-visual-studio/.+",
"surrogate.microsoft_VisualStudio_download.replacement" : "'use strict';let d=/var\\s+downloadResult\\s*=\\s*(\\{.+\\})\\s*;/,e=/(\\w+)(\\s*:(?!\\/\\/))/g;for(let f of document.getElementsByTagName('script'))try{let a=d.exec(f.innerHTML);if(a){let b=a[1].replace(/'/g,'\"');b=b.replace(e,'\"$1\"$2');let c=JSON.parse(b);if(c.downloadUrl){window.location.href=c.downloadUrl;break}}}catch(a){};",
"surrogate.goszakupki.sources" : "!https?://zakupki\\.gov\\.ru/.+",
"surrogate.goszakupki.replacement" : "'use strict';for(let el of document.querySelectorAll('[url]')){let a=document.createElement('A');a.href=el.getAttribute('url');let spn=el.getElementsByTagName('SPAN')[0];a.innerHTML=spn.innerHTML;a.className=spn.className;spn.replaceWith(a);}",
"surrogate.cloud_mail_ru.sources":"!^https://cloud\\.mail\\.ru/(stock|public)/.+$",
"surrogate.cloud_mail_ru.replacement":"'use strict';const rx=/require.config\((\{[^]+?\})\)/;const entRx=/\\x([\da-fA-F]+)/g;function getConfig(){let scripts=[...document.querySelectorAll('script:not([class]):not([src])')];let text=scripts.map((s)=>s.textContent.match(rx)).filter(j=>!!j)[0][1];text=text.replace(entRx,(...e)=>String.fromCodePoint(parseInt(e[1],16)));let config=JSON.parse(text);return config;}function getToken(){fetch('https://cloud.mail.ru/api/v2/tokens/download').then((res)=>{return res.json().then((res)=>{return new Promise(function(resolve,reject){let b=res['body'];if(b){let t=b['token'];if(t){console.log('token:',t);resolve(t);console.log('never called');}}console.error('No token present');reject('No token present: error code '+res['status']);});});}).then(token=>console.log(token));};const config=getConfig();const cls=config['config']['Cloud/settings'];const notifEl=document.querySelector('.b-page-content-loader__message-text_nojs');const stockBase=cls['dispatcher']['stock'][0]['url'];const weblinkBase=cls['dispatcher']['weblink_get'][0]['url'];var processMapping={'file':function(file,parentName){console.info(file);let fileName=file['name'];let id=file['id'];let url;if(file['dwl_token']){url=stockBase+'get/'+file['dwl_token']+'/'+encodeURIComponent(fileName);}else{url=cls['dispatcher']['weblink_get'][0]['url']+'/'+id+'/'+encodeURIComponent(fileName);}a=document.createElement('A');a.href=url;a.download=fileName;a.textContent=`${parentName}${fileName}(${file['size']}bytes,virus scan:${file['virus_scan']})`;return a;},'folder':function(folderObj,parentName){let cont=document.createElement('UL');for(var file of folderObj['list']){let child=processMapping[file['kind']](file,parentName+folderObj['id']);let it=document.createElement('LI');it.appendChild(child);cont.appendChild(it);}return cont;}};noti fEl.appendChild(processMapping['folder'](cls['folders']['folder'],''));",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this surrogate do?

Copy link
Author

@KOLANICH KOLANICH Nov 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renders files list from JS object.


"surrogate.yandex-disk.sources":"!^https://yadi\\.sk/d/\\w{13}$",
"surrogate.yandex-disk.replacement":"window.location.href='https://cloud-api.yandex.net/v1/disk/public/resources/download?public_key='+window.location.href;",

"fakeScriptLoadEvents.enabled": true,
"fakeScriptLoadEvents.onlyRequireJS": true,
"fakeScriptLoadEvents.exceptions": "",
Expand Down