diff --git a/amazon-sort-by-review.user.js b/amazon-sort-by-review.user.js index 7600cbe9..e5f399c5 100644 --- a/amazon-sort-by-review.user.js +++ b/amazon-sort-by-review.user.js @@ -1,19 +1,19 @@ // ==UserScript== // @name Amazon Sort by Review // @description Sort products best by reviews -// @version 1.3.0 +// @version 1.4.0 // @author iamogbz // @homepage https://github.com/iamogbz/oh-my-scripts // @supportURL https://github.com/iamogbz/oh-my-scripts/issues // @match *://*.amazon.ca/* // @match *://*.amazon.com/* // @match *://*.amazon.co.uk/* -// @downloadURL https://github.com/iamogbz/oh-my-scripts/raw/1.3.0/amazon-sort-by-review.user.js +// @downloadURL https://github.com/iamogbz/oh-my-scripts/raw/1.4.0/amazon-sort-by-review.user.js // @grant GM_xmlhttpRequest // @icon https://github.com/iamogbz/oh-my-scripts/raw/main/assets/monkey_128.png // @namespace iamogbz/oh-my-scripts -// @require https://github.com/iamogbz/oh-my-scripts/raw/1.3.0/lib/interval.js +// @require https://github.com/iamogbz/oh-my-scripts/raw/1.4.0/lib/interval.js // @updateURL https://github.com/iamogbz/oh-my-scripts/raw/gh-pages/amazon-sort-by-review.user.js // ==/UserScript== -(()=>{"use strict";var r,e={8492:(r,e,o)=>{const n=o(3149);!function(){const r="review-count-rank";(0,n.doEvery)({condition:()=>{const e=new URL(window.location.href).searchParams;return e.has("s")&&e.get("s")!==r},callback:()=>{const e=new URL(window.location.href);e.searchParams.set("s",r),window.location.href=e.href}})}()}},o={};function n(r){var t=o[r];if(void 0!==t)return t.exports;var s=o[r]={exports:{}};return e[r](s,s.exports,n),s.exports}n.m=e,r=[],n.O=(e,o,t,s)=>{if(!o){var a=1/0;for(h=0;h=s)&&Object.keys(n.O).every((r=>n.O[r](o[c])))?o.splice(c--,1):(i=!1,s0&&r[h-1][2]>s;h--)r[h]=r[h-1];r[h]=[o,t,s]},n.o=(r,e)=>Object.prototype.hasOwnProperty.call(r,e),(()=>{var r={89:0};n.O.j=e=>0===r[e];var e=(e,o)=>{var t,s,[a,i,c]=o,f=0;if(a.some((e=>0!==r[e]))){for(t in i)n.o(i,t)&&(n.m[t]=i[t]);if(c)var h=c(n)}for(e&&e(o);fn(8492)));t=n.O(t)})(); \ No newline at end of file +(()=>{"use strict";var r,e={4100:(r,e,o)=>{const n=o(8594);!function(){const r="review-count-rank";(0,n.doEvery)({condition:()=>{const e=new URL(window.location.href).searchParams;return e.has("s")&&e.get("s")!==r},callback:()=>{const e=new URL(window.location.href);e.searchParams.set("s",r),window.location.href=e.href}})}()}},o={};function n(r){var t=o[r];if(void 0!==t)return t.exports;var s=o[r]={exports:{}};return e[r](s,s.exports,n),s.exports}n.m=e,r=[],n.O=(e,o,t,s)=>{if(!o){var a=1/0;for(h=0;h=s)&&Object.keys(n.O).every((r=>n.O[r](o[c])))?o.splice(c--,1):(i=!1,s0&&r[h-1][2]>s;h--)r[h]=r[h-1];r[h]=[o,t,s]},n.o=(r,e)=>Object.prototype.hasOwnProperty.call(r,e),(()=>{var r={576:0};n.O.j=e=>0===r[e];var e=(e,o)=>{var t,s,[a,i,c]=o,f=0;if(a.some((e=>0!==r[e]))){for(t in i)n.o(i,t)&&(n.m[t]=i[t]);if(c)var h=c(n)}for(e&&e(o);fn(4100)));t=n.O(t)})(); \ No newline at end of file diff --git a/export-element.user.js b/export-element.user.js new file mode 100644 index 00000000..e36d3dad --- /dev/null +++ b/export-element.user.js @@ -0,0 +1,16 @@ +// ==UserScript== +// @name Export Element +// @description Add a context menu option to print a HTML element including all styles +// @version 1.4.0 +// @author iamogbz +// @homepage https://github.com/iamogbz/oh-my-scripts +// @supportURL https://github.com/iamogbz/oh-my-scripts/issues +// @match *://*/* +// @downloadURL https://github.com/iamogbz/oh-my-scripts/raw/1.4.0/export-element.user.js +// @grant GM_registerMenuCommand +// @icon https://github.com/iamogbz/oh-my-scripts/raw/main/assets/monkey_128.png +// @namespace iamogbz/oh-my-scripts +// @updateURL https://github.com/iamogbz/oh-my-scripts/raw/gh-pages/export-element.user.js +// ==/UserScript== + +(()=>{"use strict";!function(){const t=Object.freeze({PDF:"pdf"}),e={target:null,type:t.PDF};function n(t,e){for(;t;){if(e(t))return t;t=t.parentNode}return null}document.addEventListener("contextmenu",(function(t){e.target=n(t.target,(t=>!t.nextSibling))})),Object.values(t).forEach((o=>{window.GM_registerMenuCommand(`As ${o.toUpperCase()}`,(()=>{!function(o){if(e.target){if(o===t.PDF)return function(t){const e=window.open("","","width=800,height=600");if(!e)return void alert("Please allow popups for this site and try again.");const o=e.document,r=function(t,e){function n(e,n){const o=t.getComputedStyle(e);for(const t of o)n.style.setProperty(t,o.getPropertyValue(t))}const o=e.cloneNode(!0);return n(e,o),function t(e,o){const r=e;for(let e=0;e{if(!(t instanceof Element))return!1;const n=window.getComputedStyle(t).backgroundColor;if(!n)return!1;if(n===e)return!1;const o=n.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/);return!o||0!==(o[4]?parseFloat(o[4]):1)}));return o?window.getComputedStyle(o).getPropertyValue("background-color"):e}(t),e.setTimeout((()=>e.print()),1e3),e.addEventListener("afterprint",(function(){this.confirm("Close window after successful print?")&&e.close()}))}(e.target);alert(`Unsupported type: ${o}`)}else alert("Node not found!")}(o)}),`as-${o.toLowerCase()}`)}))}()})(); \ No newline at end of file diff --git a/github-file-preview-apib.user.js b/github-file-preview-apib.user.js index 31d16260..a2f91818 100644 --- a/github-file-preview-apib.user.js +++ b/github-file-preview-apib.user.js @@ -1,22 +1,22 @@ // ==UserScript== // @name GitHub File Preview APIB // @description Render Apiary blueprint files in github -// @version 1.3.0 +// @version 1.4.0 // @author iamogbz // @homepage https://github.com/iamogbz/oh-my-scripts // @supportURL https://github.com/iamogbz/oh-my-scripts/issues // @include *://github.com/* -// @downloadURL https://github.com/iamogbz/oh-my-scripts/raw/1.3.0/github-file-preview-apib.user.js +// @downloadURL https://github.com/iamogbz/oh-my-scripts/raw/1.4.0/github-file-preview-apib.user.js // @grant GM_xmlhttpRequest // @icon https://github.com/iamogbz/oh-my-scripts/raw/main/assets/monkey_128.png // @namespace iamogbz/oh-my-scripts -// @require https://github.com/iamogbz/oh-my-scripts/raw/1.3.0/lib/dom.js -// @require https://github.com/iamogbz/oh-my-scripts/raw/1.3.0/lib/github-file.js -// @require https://github.com/iamogbz/oh-my-scripts/raw/1.3.0/lib/github.js -// @require https://github.com/iamogbz/oh-my-scripts/raw/1.3.0/lib/paths.js -// @require https://github.com/iamogbz/oh-my-scripts/raw/1.3.0/lib/request.js -// @require https://github.com/iamogbz/oh-my-scripts/raw/1.3.0/lib/ns.js +// @require https://github.com/iamogbz/oh-my-scripts/raw/1.4.0/lib/dom.js +// @require https://github.com/iamogbz/oh-my-scripts/raw/1.4.0/lib/github-file.js +// @require https://github.com/iamogbz/oh-my-scripts/raw/1.4.0/lib/github.js +// @require https://github.com/iamogbz/oh-my-scripts/raw/1.4.0/lib/paths.js +// @require https://github.com/iamogbz/oh-my-scripts/raw/1.4.0/lib/request.js +// @require https://github.com/iamogbz/oh-my-scripts/raw/1.4.0/lib/ns.js // @updateURL https://github.com/iamogbz/oh-my-scripts/raw/gh-pages/github-file-preview-apib.user.js // ==/UserScript== -(()=>{"use strict";var e,r={7554:(e,r,t)=>{const n=t(3319),o=t(7594);class l extends n.ExtendFilePreview{constructor(){const e=n.filePreviewNS`extend-apib`;super(e,e,new Set(["apib"]))}prepareHTML(e){const r=btoa(e);return(0,o.request)("https://d31myey2oeipxs.cloudfront.net/v1",{headers:{"X-Blueprint":r}}).then((e=>{var r;return null===(r=e.text)||void 0===r?void 0:r.call(e)})).then((e=>null==e?void 0:e.replace(/{if(!t){var a=1/0;for(i=0;i=l)&&Object.keys(n.O).every((e=>n.O[e](t[p])))?t.splice(p--,1):(s=!1,l0&&e[i-1][2]>l;i--)e[i]=e[i-1];e[i]=[t,o,l]},n.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),(()=>{var e={340:0};n.O.j=r=>0===e[r];var r=(r,t)=>{var o,l,[a,s,p]=t,c=0;if(a.some((r=>0!==e[r]))){for(o in s)n.o(s,o)&&(n.m[o]=s[o]);if(p)var i=p(n)}for(r&&r(t);cn(7554)));o=n.O(o)})(); \ No newline at end of file +(()=>{"use strict";var e,r={6690:(e,r,t)=>{const n=t(2639),o=t(8730);class l extends n.ExtendFilePreview{constructor(){const e=n.filePreviewNS`extend-apib`;super(e,e,new Set(["apib"]))}prepareHTML(e){const r=btoa(e);return(0,o.request)("https://d31myey2oeipxs.cloudfront.net/v1",{headers:{"X-Blueprint":r}}).then((e=>{var r;return null===(r=e.text)||void 0===r?void 0:r.call(e)})).then((e=>null==e?void 0:e.replace(/{if(!t){var a=1/0;for(i=0;i=l)&&Object.keys(n.O).every((e=>n.O[e](t[p])))?t.splice(p--,1):(s=!1,l0&&e[i-1][2]>l;i--)e[i]=e[i-1];e[i]=[t,o,l]},n.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),(()=>{var e={984:0};n.O.j=r=>0===e[r];var r=(r,t)=>{var o,l,[a,s,p]=t,c=0;if(a.some((r=>0!==e[r]))){for(o in s)n.o(s,o)&&(n.m[o]=s[o]);if(p)var i=p(n)}for(r&&r(t);cn(6690)));o=n.O(o)})(); \ No newline at end of file diff --git a/github-file-preview-html.user.js b/github-file-preview-html.user.js index c1ef0043..ba5de8dd 100644 --- a/github-file-preview-html.user.js +++ b/github-file-preview-html.user.js @@ -1,24 +1,24 @@ // ==UserScript== // @name GitHub File Preview HTML // @description Render HTML files in github -// @version 1.3.0 +// @version 1.4.0 // @author iamogbz // @homepage https://github.com/iamogbz/oh-my-scripts // @supportURL https://github.com/iamogbz/oh-my-scripts/issues // @include *://github.com/* -// @downloadURL https://github.com/iamogbz/oh-my-scripts/raw/1.3.0/github-file-preview-html.user.js +// @downloadURL https://github.com/iamogbz/oh-my-scripts/raw/1.4.0/github-file-preview-html.user.js // @grant GM_xmlhttpRequest // @icon https://github.com/iamogbz/oh-my-scripts/raw/main/assets/monkey_128.png // @namespace iamogbz/oh-my-scripts -// @require https://github.com/iamogbz/oh-my-scripts/raw/1.3.0/lib/dom.js -// @require https://github.com/iamogbz/oh-my-scripts/raw/1.3.0/lib/github-file.js -// @require https://github.com/iamogbz/oh-my-scripts/raw/1.3.0/lib/github.js -// @require https://github.com/iamogbz/oh-my-scripts/raw/1.3.0/lib/paths.js -// @require https://github.com/iamogbz/oh-my-scripts/raw/1.3.0/lib/request.js -// @require https://github.com/iamogbz/oh-my-scripts/raw/1.3.0/lib/ns.js -// @require https://github.com/iamogbz/oh-my-scripts/raw/1.3.0/npm/.pnpm.js -// @require https://github.com/iamogbz/oh-my-scripts/raw/1.3.0/lib/dom-inline.js +// @require https://github.com/iamogbz/oh-my-scripts/raw/1.4.0/lib/dom.js +// @require https://github.com/iamogbz/oh-my-scripts/raw/1.4.0/lib/github-file.js +// @require https://github.com/iamogbz/oh-my-scripts/raw/1.4.0/lib/github.js +// @require https://github.com/iamogbz/oh-my-scripts/raw/1.4.0/lib/paths.js +// @require https://github.com/iamogbz/oh-my-scripts/raw/1.4.0/lib/request.js +// @require https://github.com/iamogbz/oh-my-scripts/raw/1.4.0/lib/ns.js +// @require https://github.com/iamogbz/oh-my-scripts/raw/1.4.0/npm/.pnpm.js +// @require https://github.com/iamogbz/oh-my-scripts/raw/1.4.0/lib/dom-inline.js // @updateURL https://github.com/iamogbz/oh-my-scripts/raw/gh-pages/github-file-preview-html.user.js // ==/UserScript== -(()=>{var e,t={9660:(e,t,r)=>{"use strict";const n=r(7725),o=r(3319),i=r(2041);class l extends o.ExtendFilePreview{constructor(){const e=o.filePreviewNS`extend-html`;super(e,e,new Set(["html","xhtml"]))}prepareHTML(e,t){return(0,n.inline)({base:(0,i.fileDirname)(this.pathToBlob(t)),folder:(0,i.fileDirname)(t),html:e.replace(/{}},r={};function n(e){var o=r[e];if(void 0!==o)return o.exports;var i=r[e]={id:e,loaded:!1,exports:{}};return t[e].call(i.exports,i,i.exports,n),i.loaded=!0,i.exports}n.m=t,e=[],n.O=(t,r,o,i)=>{if(!r){var l=1/0;for(h=0;h=i)&&Object.keys(n.O).every((e=>n.O[e](r[a])))?r.splice(a--,1):(s=!1,i0&&e[h-1][2]>i;h--)e[h]=e[h-1];e[h]=[r,o,i]},n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.nmd=e=>(e.paths=[],e.children||(e.children=[]),e),(()=>{var e={582:0};n.O.j=t=>0===e[t];var t=(t,r)=>{var o,i,[l,s,a]=r,c=0;if(l.some((t=>0!==e[t]))){for(o in s)n.o(s,o)&&(n.m[o]=s[o]);if(a)var h=a(n)}for(t&&t(r);cn(9660)));o=n.O(o)})(); \ No newline at end of file +(()=>{var e,t={6731:(e,t,r)=>{"use strict";const n=r(2933),o=r(2639),i=r(7131);class l extends o.ExtendFilePreview{constructor(){const e=o.filePreviewNS`extend-html`;super(e,e,new Set(["html","xhtml"]))}prepareHTML(e,t){return(0,n.inline)({base:(0,i.fileDirname)(this.pathToBlob(t)),folder:(0,i.fileDirname)(t),html:e.replace(/{}},r={};function n(e){var o=r[e];if(void 0!==o)return o.exports;var i=r[e]={id:e,loaded:!1,exports:{}};return t[e].call(i.exports,i,i.exports,n),i.loaded=!0,i.exports}n.m=t,e=[],n.O=(t,r,o,i)=>{if(!r){var l=1/0;for(h=0;h=i)&&Object.keys(n.O).every((e=>n.O[e](r[a])))?r.splice(a--,1):(s=!1,i0&&e[h-1][2]>i;h--)e[h]=e[h-1];e[h]=[r,o,i]},n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.nmd=e=>(e.paths=[],e.children||(e.children=[]),e),(()=>{var e={697:0};n.O.j=t=>0===e[t];var t=(t,r)=>{var o,i,[l,s,a]=r,c=0;if(l.some((t=>0!==e[t]))){for(o in s)n.o(s,o)&&(n.m[o]=s[o]);if(a)var h=a(n)}for(t&&t(r);cn(6731)));o=n.O(o)})(); \ No newline at end of file diff --git a/lib/dom-inline.js b/lib/dom-inline.js index eb3f2407..c0bfd8cc 100644 --- a/lib/dom-inline.js +++ b/lib/dom-inline.js @@ -1 +1 @@ -"use strict";(self.webpackChunkoh_my_scripts=self.webpackChunkoh_my_scripts||[]).push([[232],{7725:function(t,e,n){var s=this&&this.__awaiter||function(t,e,n,s){return new(n||(n=Promise))((function(o,c){function i(t){try{a(s.next(t))}catch(t){c(t)}}function r(t){try{a(s.throw(t))}catch(t){c(t)}}function a(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(i,r)}a((s=s.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0}),e.inline=void 0,n(1801);const o=n(2041);function c(t){return(0,o.isAbsolutePath)(t)||t.startsWith("/")}e.inline=function({base:t,html:e,folder:n="",load:i=(()=>Promise.resolve(""))}){return s(this,void 0,void 0,(function*(){const r=window.cheerio.load(e),a={css:{callback:t=>s(this,void 0,void 0,(function*(){const e=r(t).attr("href");if(e)return(t=>{const e=c(t);return i(e?t:(0,o.normalisePath)(`${n}/${t}`))})(e).then((t=>{!function(t,e,n,s="",o={}){const c=document.createElement(n);for(const[t,e]of Object.entries(o))c.setAttribute(t,`${e}`);c.innerHTML=s,t(e).append(c.outerHTML)}(r,"head","style",t,{type:"text/css"})}))})),cleanup:!0,selector:'link[rel="stylesheet"]',tasks:[]},img:{callback:e=>s(this,void 0,void 0,(function*(){const n=r(e).attr("src");if(!n)return;const s=c(n)?n:`${t}/${n}`;r(e).attr("src",s)})),selector:"img",tasks:[]},js:{callback:()=>s(this,void 0,void 0,(function*(){})),cleanup:!0,selector:'script[src*=".js"]',tasks:[]}},l=[];for(const[,t]of Object.entries(a)){if(!t.selector)continue;const e=r(t.selector);e.each(((e,n)=>t.tasks.push(t.callback(n)))),l.push(Promise.all(t.tasks).then((()=>t.cleanup&&e.remove())))}return yield Promise.all(l),r.html()}))}}}]); \ No newline at end of file +"use strict";(self.webpackChunkoh_my_scripts=self.webpackChunkoh_my_scripts||[]).push([[793],{2933:function(t,e,n){var s=this&&this.__awaiter||function(t,e,n,s){return new(n||(n=Promise))((function(c,o){function i(t){try{a(s.next(t))}catch(t){o(t)}}function r(t){try{a(s.throw(t))}catch(t){o(t)}}function a(t){var e;t.done?c(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(i,r)}a((s=s.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0}),e.inline=function(t){return s(this,arguments,void 0,(function*({base:t,html:e,folder:n="",load:i=(()=>Promise.resolve(""))}){const r=window.cheerio.load(e),a={css:{callback:t=>s(this,void 0,void 0,(function*(){const e=r(t).attr("href");if(e)return(t=>{const e=o(t);return i(e?t:(0,c.normalisePath)(`${n}/${t}`))})(e).then((t=>{!function(t,e,n,s="",c={}){const o=document.createElement(n);for(const[t,e]of Object.entries(c))o.setAttribute(t,`${e}`);o.innerHTML=s,t(e).append(o.outerHTML)}(r,"head","style",t,{type:"text/css"})}))})),cleanup:!0,selector:'link[rel="stylesheet"]',tasks:[]},img:{callback:e=>s(this,void 0,void 0,(function*(){const n=r(e).attr("src");if(!n)return;const s=o(n)?n:`${t}/${n}`;r(e).attr("src",s)})),selector:"img",tasks:[]},js:{callback:()=>s(this,void 0,void 0,(function*(){})),cleanup:!0,selector:'script[src*=".js"]',tasks:[]}},l=[];for(const[,t]of Object.entries(a)){if(!t.selector)continue;const e=r(t.selector);e.each(((e,n)=>t.tasks.push(t.callback(n)))),l.push(Promise.all(t.tasks).then((()=>t.cleanup&&e.remove())))}return yield Promise.all(l),r.html()}))},n(358);const c=n(7131);function o(t){return(0,c.isAbsolutePath)(t)||t.startsWith("/")}}}]); \ No newline at end of file diff --git a/lib/dom.js b/lib/dom.js index 1f3f082c..f4f6e246 100644 --- a/lib/dom.js +++ b/lib/dom.js @@ -1 +1 @@ -"use strict";(self.webpackChunkoh_my_scripts=self.webpackChunkoh_my_scripts||[]).push([[509],{6193:function(e,t){var n=this&&this.__awaiter||function(e,t,n,o){return new(n||(n=Promise))((function(r,c){function i(e){try{u(o.next(e))}catch(e){c(e)}}function s(e){try{u(o.throw(e))}catch(e){c(e)}}function u(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,s)}u((o=o.apply(e,t||[])).next())}))};function o(e){return"string"==typeof(null==e?void 0:e.tagName)}function r(e){return e instanceof Element||e instanceof HTMLDocument}function c(e){return null!=e?e:document}function i(e){return"math"===e?"http://www.w3.org/1998/Math/MathML":"svg"===e?"http://www.w3.org/2000/svg":"http://www.w3.org/1999/xhtml"}function s(e,t){var n;return null===(n=c(t))||void 0===n?void 0:n.querySelector(`${e}`)}function u(e,t){const n=s(e,t);if(!n)throw new Error(`Not found: ${e}, ${t}`);return n}Object.defineProperty(t,"__esModule",{value:!0}),t.observeEl=t.createElementStyle=t.createElement=t.selectOrReject=t.selectOrThrow=t.selectExists=t.selectDOM=t.selectAll=t.getTagNS=void 0,t.getTagNS=i,t.selectAll=function(e,t){return Array.from(c(t).querySelectorAll(e))},t.selectDOM=s,t.selectExists=function(e,t){return Boolean(s(e,t))},t.selectOrThrow=u,t.selectOrReject=function(e,t,o=300,r=3){return n(this,void 0,void 0,(function*(){let n=0,c=null,i=null;for(;nsetTimeout(e,o)))}}if(!i)throw c;return i}))},t.createElement=function e({attributes:t={},children:n=[],events:c={},tagName:s,tagNS:u,reuse:l}){const a=null!=l?l:document.createElementNS(u||i(s),s);a.innerHTML="";for(const[e,t]of(f=c,Object.entries(f)))a.addEventListener(e,t);var f;for(const[e,n]of Object.entries(t))("boolean"!=typeof n||n)&&a.setAttribute(e,`${n}`);const d=["boolean","function","symbol","undefined"];for(const t of n)!t||d.includes(typeof t)?console.error(`Appending child of type '${t}' is not supported.`):r(t)?a.appendChild(t):o(t)?a.appendChild(e(t)):a.appendChild(document.createTextNode(`${t}`));return a},t.createElementStyle=function(e={}){return Object.entries(e).map((([e,t])=>`${e}: ${t};`)).join(" ")},t.observeEl=function(e,t,n={childList:!0}){let o=!1;const r=new MutationObserver(t),c=new MutationObserver((()=>{if(o)return void c.disconnect();const i="string"==typeof e?s(e):e;i&&(r.observe(i,n),t.call(r,[],r),o=!0,c.disconnect())}));return c.observe(document.getRootNode(),{childList:!0,subtree:!0}),r}}}]); \ No newline at end of file +"use strict";(self.webpackChunkoh_my_scripts=self.webpackChunkoh_my_scripts||[]).push([[461],{9091:function(e,t){var n=this&&this.__awaiter||function(e,t,n,o){return new(n||(n=Promise))((function(r,c){function i(e){try{s(o.next(e))}catch(e){c(e)}}function u(e){try{s(o.throw(e))}catch(e){c(e)}}function s(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,u)}s((o=o.apply(e,t||[])).next())}))};function o(e){return"string"==typeof(null==e?void 0:e.tagName)}function r(e){return e instanceof Element||e instanceof HTMLDocument}function c(e){return null!=e?e:document}function i(e){return"math"===e?"http://www.w3.org/1998/Math/MathML":"svg"===e?"http://www.w3.org/2000/svg":"http://www.w3.org/1999/xhtml"}function u(e,t){var n;return null===(n=c(t))||void 0===n?void 0:n.querySelector(`${e}`)}function s(e,t){const n=u(e,t);if(!n)throw new Error(`Not found: ${e}, ${t}`);return n}Object.defineProperty(t,"__esModule",{value:!0}),t.getTagNS=i,t.selectAll=function(e,t){return Array.from(c(t).querySelectorAll(e))},t.selectDOM=u,t.selectExists=function(e,t){return Boolean(u(e,t))},t.selectOrThrow=s,t.selectOrReject=function(e,t){return n(this,arguments,void 0,(function*(e,t,n=300,o=3){let r=0,c=null,i=null;for(;rsetTimeout(e,n)))}}if(!i)throw c;return i}))},t.createElement=function e({attributes:t={},children:n=[],events:c={},tagName:u,tagNS:s,reuse:l}){const f=null!=l?l:document.createElementNS(s||i(u),u);f.innerHTML="";for(const[e,t]of(a=c,Object.entries(a)))f.addEventListener(e,t);var a;for(const[e,n]of Object.entries(t))("boolean"!=typeof n||n)&&f.setAttribute(e,`${n}`);const d=["boolean","function","symbol","undefined"];for(const t of n)!t||d.includes(typeof t)?console.error(`Appending child of type '${t}' is not supported.`):r(t)?f.appendChild(t):o(t)?f.appendChild(e(t)):f.appendChild(document.createTextNode(`${t}`));return f},t.createElementStyle=function(e={}){return Object.entries(e).map((([e,t])=>`${e}: ${t};`)).join(" ")},t.observeEl=function(e,t,n={childList:!0}){let o=!1;const r=new MutationObserver(t),c=new MutationObserver((()=>{if(o)return void c.disconnect();const i="string"==typeof e?u(e):e;i&&(r.observe(i,n),t.call(r,[],r),o=!0,c.disconnect())}));return c.observe(document.getRootNode(),{childList:!0,subtree:!0}),r}}}]); \ No newline at end of file diff --git a/lib/github-file.js b/lib/github-file.js index ee2bd418..f38effd3 100644 --- a/lib/github-file.js +++ b/lib/github-file.js @@ -1 +1 @@ -"use strict";(self.webpackChunkoh_my_scripts=self.webpackChunkoh_my_scripts||[]).push([[610],{3319:function(e,t,i){var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(l,r){function n(e){try{a(s.next(e))}catch(e){r(e)}}function o(e){try{a(s.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?l(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(n,o)}a((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.ExtendFilePreview=t.filePreviewNS=void 0;const l=i(6193),r=i(4337),n=i(2041),o=i(7594);t.filePreviewNS=function(e){return`iamogbz-gh-file-preview-${e}`},t.ExtendFilePreview=class{constructor(e,t,i){this.frameTagName="iframe",this.toggleActionSource="source",this.toggleActionRender="render",this.frameStyle={background:"white",border:"none",display:"block",height:"100%",left:0,padding:0,position:"absolute",top:0,width:"100%"},this.id=e,this.featureClass=t,this.fileTypes=i}initCondition(){return(0,r.isCommit)()||(0,r.isCompare)()||(0,r.isPRFiles)()||(0,r.isSingleFile)()}setup(){const e=()=>{this.initCondition()&&this.initFeature()};let t=null;(0,l.observeEl)(document.body,(()=>{t&&t===window.location.href||(t=window.location.href,e())}),{childList:!0,subtree:!0})}pathToFile(e){return`${(0,r.getUserRepo)()}/${e}`}pathToBlob(e){return`https://raw.githubusercontent.com/${this.pathToFile(e)}`}getFileContent(e){return this.safeFetch((0,n.isAbsolutePath)(e)?e:this.pathToBlob(e)).then((e=>{var t;return null===(t=e.text)||void 0===t?void 0:t.call(e)})).catch((t=>{if(console.info(t),(0,n.isAbsolutePath)(e))return;const[i,...s]=e.split("/");return r.githubApi.v3(`${this.pathToApi(s.join("/"))}?ref=${i}`).then((e=>atob(e.content))).catch((e=>{console.error(e)}))}))}safeFetch(e,t){return(0,o.request)(e,t).then((e=>{if(200!==e.status)throw new Error(`${e.status} - ${e.statusText}`);return e}))}isSupportedFile(e){return this.fileTypes.has((0,n.getFileType)(e))}pathToApi(e){return`repos/${(0,r.getUserRepo)()}/contents/${e}`}selectButton(e){const t=(0,l.selectDOM)(`.BtnGroup.${this.featureClass} .BtnGroup-item.selected`);t&&t.classList.remove("selected"),e.classList.add("selected"),e.blur()}showSource(e){return t=>{const i=t.currentTarget;if(i.disabled||!e)return;e.style.visibility="hidden";const s=e.parentElement;return null==s||s.style.removeProperty("overflow"),null==s||s.style.removeProperty("height"),null==s||s.style.removeProperty("max-height"),this.selectButton(i)}}showRendered(e){return t=>{const i=t.currentTarget,s=this.getContainerElement(e),l=this.getScrollHeight(e);if(!s||!l||i.disabled)return;e.style.visibility="visible",s.style.overflow="hidden";const r=`${l}px`;return s.style.height=r,s.style.maxHeight=r,s.scrollLeft=0,this.selectButton(i)}}getContainerElement(e){return e.parentElement}getScrollHeight(e){return e.contentWindow?e.contentWindow.document.body.scrollHeight+32:0}updateToggle(e,t){var i;e.disabled=!t,e.dataset.toggleAction===this.toggleActionRender&&(e.onclick=this.showRendered(t)),e.dataset.toggleAction===this.toggleActionSource&&(e.onclick=this.showSource(t)),e.setAttribute("aria-label",null!==(i=e.disabled?e.dataset.labelDisabled:e.dataset.labelEnabled)&&void 0!==i?i:"")}viewerButtonToggleGroup({frameElem:e,isFileList:t}){var i;const s=!e,r="Render toggle disabled",n=(0,l.getTagNS)("svg"),o=(0,l.createElement)({attributes:{"aria-current":"true",class:`btn btn-sm BtnGroup-item tooltipped tooltipped-${t?"w":"n"} source ${t?"js-source":""} ${t?"":"selected"}`,"data-disable-with":"","data-label-disabled":r,"data-label-enabled":"Display the source "+(t?"diff":"blob"),"data-toggle-action":this.toggleActionSource,disabled:s},children:[{attributes:{"aria-hidden":"true",class:"octicon octicon-code",height:16,version:"1.1",viewBox:"0 0 16 16",width:16},children:[{attributes:{d:"M4.72 3.22a.75.75 0 011.06 1.06L2.06 8l3.72 3.72a.75.75 0 11-1.06 1.06L.47 8.53a.75.75 0 010-1.06l4.25-4.25zm6.56 0a.75.75 0 10-1.06 1.06L13.94 8l-3.72 3.72a.75.75 0 101.06 1.06l4.25-4.25a.75.75 0 000-1.06l-4.25-4.25z","fill-rule":"evenodd"},tagName:"path",tagNS:n}],tagName:"svg",tagNS:n}],events:{click:this.showSource(e)},tagName:"button"}),a=(0,l.createElement)({attributes:{class:`btn btn-sm BtnGroup-item tooltipped tooltipped-${t?"w":"n"} rendered ${t?"js-rendered":""}`,disabled:s,"data-disable-with":"","data-label-disabled":r,"data-label-enabled":"Display the "+(t?"rich diff":"rendered blob"),"data-toggle-action":this.toggleActionRender},children:[{attributes:{"aria-hidden":"true",class:"octicon octicon-file",height:16,version:"1.1",viewBox:"0 0 16 16",width:16},children:[{attributes:{d:"M3.75 1.5a.25.25 0 00-.25.25v11.5c0 .138.112.25.25.25h8.5a.25.25 0 00.25-.25V6H9.75A1.75 1.75 0 018 4.25V1.5H3.75zm5.75.56v2.19c0 .138.112.25.25.25h2.19L9.5 2.06zM2 1.75C2 .784 2.784 0 3.75 0h5.086c.464 0 .909.184 1.237.513l3.414 3.414c.329.328.513.773.513 1.237v8.086A1.75 1.75 0 0112.25 15h-8.5A1.75 1.75 0 012 13.25V1.75z","fill-rule":"evenodd"},tagName:"path",tagNS:n}],tagName:"svg",tagNS:n}],events:{click:this.showRendered(e)},tagName:"button"});this.updateToggle(o,e),this.updateToggle(a,e);const d=`${e.id}-button-group`,c=`BtnGroup ${this.featureClass}`;return(0,l.createElement)({attributes:{id:d,class:c},children:[o,a],tagName:"span",reuse:null!==(i=document.getElementById(d))&&void 0!==i?i:void 0})}fileViewerButtonToggle({actionsElem:e,frameElem:t}){var i,s;const l=`${t.id}-button-group`,r=document.getElementById(l),n=null!=r?r:document.createElement("li"),o="aria-current",a=`button[${o}]`,d=e=>"true"===e.getAttribute(o),c=Array.from(e.querySelectorAll(a)),u=c.filter(d)[0],h=null==u?void 0:u.getAttribute("class"),m=null===(i=null==u?void 0:u.parentElement)||void 0===i?void 0:i.getAttribute("class"),g=c.filter((e=>!d(e)))[0],b=null==g?void 0:g.getAttribute("class"),p=null===(s=null==g?void 0:g.parentElement)||void 0===s?void 0:s.getAttribute("class");if(!r){n.innerHTML=`\x3c!-- github-file-${this.id}-created-button --\x3e`,n.id=l,n.className=null!=p?p:"";const e=n.querySelector(a),i=e=>{var t;e.setAttribute(o,"true"),h&&e.setAttribute("class",h),m&&(null===(t=e.parentElement)||void 0===t||t.setAttribute("class",m))},s=e=>{var t;e.setAttribute(o,"false"),b&&e.setAttribute("class",b),m&&(null===(t=e.parentElement)||void 0===t||t.setAttribute("class",m))};n.addEventListener("click",(l=>{this.showRendered(t)(l),c.forEach(s),e&&i(e)})),c.forEach((l=>{l.addEventListener("click",(r=>{this.showSource(t)(r),i(l),e&&s(e)}))}))}return n}getFrameElem(e){const t=`${this.frameTagName}.${this.featureClass}`;return(0,l.selectDOM)(t,null!=e?e:document.body)}frameElement(e,t){var i;const s=this.getFrameElem(t);return(0,l.createElement)({attributes:Object.assign({class:this.featureClass,style:(0,l.createElementStyle)(Object.assign({visibility:null!==(i=null==s?void 0:s.style.visibility)&&void 0!==i?i:"hidden"},this.frameStyle))},e),tagName:this.frameTagName,reuse:this.getFrameElem(t)})}addButtonsToFileHeaderActions(e,t){var i;const s=`.BtnGroup.${this.featureClass}`;if((0,l.selectExists)(s,e))return void(null===(i=(0,l.selectDOM)(s,e))||void 0===i||i.childNodes.forEach((e=>{this.updateToggle(e,t)})));const n=(0,r.isPRFiles)()||(0,r.isCommit)()||(0,r.isCompare)();n&&(e.style.alignItems="center"),e.insertBefore(n?this.viewerButtonToggleGroup({frameElem:t,isFileList:n}):this.fileViewerButtonToggle({actionsElem:e,frameElem:t}),e.firstChild)}addFrameToFileBody(e,t,i){return s(this,void 0,void 0,(function*(){if(i&&!(0,l.selectExists)(".js-blob-wrapper",e))return;const s={"data-filepath":t,src:`https://rawgit.com/${this.pathToFile(t)}`,srcDoc:yield this.prepareHTML(yield this.getFileContent(t),t)},r=this.frameElement(s,e);return e.style.position="relative",(0,l.observeEl)(e,(()=>{e.lastElementChild!==r&&e.appendChild(r)}),{childList:!0,subtree:!0}),r}))}extendHtmlFileDetailsElements(e){return()=>Promise.all((0,l.selectAll)(".file.Details").map((t=>s(this,void 0,void 0,(function*(){const i=(0,l.selectOrThrow)(".file-header",t);if(!i.dataset.path)return;const s=`${e}/${i.dataset.path}`;if(this.isSupportedFile(s))try{const e=yield this.addFrameToFileBody((0,l.selectOrThrow)(".js-file-content",t),s,!0);if(!e)return;this.addButtonsToFileHeaderActions((0,l.selectOrThrow)(".file-actions>.d-flex",i),e)}catch(e){console.error(e)}})))))}initDiff(e){if(!e)return;const t=this.extendHtmlFileDetailsElements(e);(0,l.observeEl)("#files",t,{childList:!0,subtree:!0})}initCommit(){this.initDiff((0,r.getCommitSha)())}initCompare(){this.initDiff((0,r.getCompareHeadSha)())}initPRFiles(){var e;this.initDiff(null===(e=(0,l.selectDOM)(".js-reviews-container #head_sha"))||void 0===e?void 0:e.value)}initSingleFile(){return s(this,void 0,void 0,(function*(){const e=(0,r.getRepoPath)().replace("blob/","");if(!this.isSupportedFile(e)){const e=this.getFrameElem();return void(e&&(e.style.visibility="hidden"))}const t=yield this.addFrameToFileBody(yield(0,l.selectOrReject)("section[aria-labelledby='file-name-id']"),e,!1);t&&this.addButtonsToFileHeaderActions(yield(0,l.selectOrReject)("ul[aria-label='File view']"),t)}))}initFeature(){const e=(0,r.isPRFiles)()&&this.initPRFiles(),t=(0,r.isSingleFile)()&&this.initSingleFile(),i=(0,r.isCommit)()&&this.initCommit(),s=(0,r.isCompare)()&&this.initCompare();return Promise.all([e,t,i,s]).then((e=>e.some(Boolean)))}}}}]); \ No newline at end of file +"use strict";(self.webpackChunkoh_my_scripts=self.webpackChunkoh_my_scripts||[]).push([[645],{2639:function(e,t,i){var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(l,r){function n(e){try{a(s.next(e))}catch(e){r(e)}}function o(e){try{a(s.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?l(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(n,o)}a((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.ExtendFilePreview=void 0,t.filePreviewNS=function(e){return`iamogbz-gh-file-preview-${e}`};const l=i(9091),r=i(6116),n=i(7131),o=i(8730);t.ExtendFilePreview=class{constructor(e,t,i){this.frameTagName="iframe",this.toggleActionSource="source",this.toggleActionRender="render",this.frameStyle={background:"white",border:"none",display:"block",height:"100%",left:0,padding:0,position:"absolute",top:0,width:"100%"},this.id=e,this.featureClass=t,this.fileTypes=i}initCondition(){return(0,r.isCommit)()||(0,r.isCompare)()||(0,r.isPRFiles)()||(0,r.isSingleFile)()}setup(){const e=()=>{this.initCondition()&&this.initFeature()};let t=null;(0,l.observeEl)(document.body,(()=>{t&&t===window.location.href||(t=window.location.href,e())}),{childList:!0,subtree:!0})}pathToFile(e){return`${(0,r.getUserRepo)()}/${e}`}pathToBlob(e){return`https://raw.githubusercontent.com/${this.pathToFile(e)}`}getFileContent(e){return this.safeFetch((0,n.isAbsolutePath)(e)?e:this.pathToBlob(e)).then((e=>{var t;return null===(t=e.text)||void 0===t?void 0:t.call(e)})).catch((t=>{if(console.info(t),(0,n.isAbsolutePath)(e))return;const[i,...s]=e.split("/");return r.githubApi.v3(`${this.pathToApi(s.join("/"))}?ref=${i}`).then((e=>atob(e.content))).catch((e=>{console.error(e)}))}))}safeFetch(e,t){return(0,o.request)(e,t).then((e=>{if(200!==e.status)throw new Error(`${e.status} - ${e.statusText}`);return e}))}isSupportedFile(e){return this.fileTypes.has((0,n.getFileType)(e))}pathToApi(e){return`repos/${(0,r.getUserRepo)()}/contents/${e}`}selectButton(e){const t=(0,l.selectDOM)(`.BtnGroup.${this.featureClass} .BtnGroup-item.selected`);t&&t.classList.remove("selected"),e.classList.add("selected"),e.blur()}showSource(e){return t=>{const i=t.currentTarget;if(i.disabled||!e)return;e.style.visibility="hidden";const s=e.parentElement;return null==s||s.style.removeProperty("overflow"),null==s||s.style.removeProperty("height"),null==s||s.style.removeProperty("max-height"),this.selectButton(i)}}showRendered(e){return t=>{const i=t.currentTarget,s=this.getContainerElement(e),l=this.getScrollHeight(e);if(!s||!l||i.disabled)return;e.style.visibility="visible",s.style.overflow="hidden";const r=`${l}px`;return s.style.height=r,s.style.maxHeight=r,s.scrollLeft=0,this.selectButton(i)}}getContainerElement(e){return e.parentElement}getScrollHeight(e){return e.contentWindow?e.contentWindow.document.body.scrollHeight+32:0}updateToggle(e,t){var i;e.disabled=!t,e.dataset.toggleAction===this.toggleActionRender&&(e.onclick=this.showRendered(t)),e.dataset.toggleAction===this.toggleActionSource&&(e.onclick=this.showSource(t)),e.setAttribute("aria-label",null!==(i=e.disabled?e.dataset.labelDisabled:e.dataset.labelEnabled)&&void 0!==i?i:"")}viewerButtonToggleGroup({frameElem:e,isFileList:t}){var i;const s=!e,r="Render toggle disabled",n=(0,l.getTagNS)("svg"),o=(0,l.createElement)({attributes:{"aria-current":"true",class:`btn btn-sm BtnGroup-item tooltipped tooltipped-${t?"w":"n"} source ${t?"js-source":""} ${t?"":"selected"}`,"data-disable-with":"","data-label-disabled":r,"data-label-enabled":"Display the source "+(t?"diff":"blob"),"data-toggle-action":this.toggleActionSource,disabled:s},children:[{attributes:{"aria-hidden":"true",class:"octicon octicon-code",height:16,version:"1.1",viewBox:"0 0 16 16",width:16},children:[{attributes:{d:"M4.72 3.22a.75.75 0 011.06 1.06L2.06 8l3.72 3.72a.75.75 0 11-1.06 1.06L.47 8.53a.75.75 0 010-1.06l4.25-4.25zm6.56 0a.75.75 0 10-1.06 1.06L13.94 8l-3.72 3.72a.75.75 0 101.06 1.06l4.25-4.25a.75.75 0 000-1.06l-4.25-4.25z","fill-rule":"evenodd"},tagName:"path",tagNS:n}],tagName:"svg",tagNS:n}],events:{click:this.showSource(e)},tagName:"button"}),a=(0,l.createElement)({attributes:{class:`btn btn-sm BtnGroup-item tooltipped tooltipped-${t?"w":"n"} rendered ${t?"js-rendered":""}`,disabled:s,"data-disable-with":"","data-label-disabled":r,"data-label-enabled":"Display the "+(t?"rich diff":"rendered blob"),"data-toggle-action":this.toggleActionRender},children:[{attributes:{"aria-hidden":"true",class:"octicon octicon-file",height:16,version:"1.1",viewBox:"0 0 16 16",width:16},children:[{attributes:{d:"M3.75 1.5a.25.25 0 00-.25.25v11.5c0 .138.112.25.25.25h8.5a.25.25 0 00.25-.25V6H9.75A1.75 1.75 0 018 4.25V1.5H3.75zm5.75.56v2.19c0 .138.112.25.25.25h2.19L9.5 2.06zM2 1.75C2 .784 2.784 0 3.75 0h5.086c.464 0 .909.184 1.237.513l3.414 3.414c.329.328.513.773.513 1.237v8.086A1.75 1.75 0 0112.25 15h-8.5A1.75 1.75 0 012 13.25V1.75z","fill-rule":"evenodd"},tagName:"path",tagNS:n}],tagName:"svg",tagNS:n}],events:{click:this.showRendered(e)},tagName:"button"});this.updateToggle(o,e),this.updateToggle(a,e);const d=`${e.id}-button-group`,c=`BtnGroup ${this.featureClass}`;return(0,l.createElement)({attributes:{id:d,class:c},children:[o,a],tagName:"span",reuse:null!==(i=document.getElementById(d))&&void 0!==i?i:void 0})}fileViewerButtonToggle({actionsElem:e,frameElem:t}){var i,s;const l=`${t.id}-button-group`,r=document.getElementById(l),n=null!=r?r:document.createElement("li"),o="aria-current",a=`button[${o}]`,d=e=>"true"===e.getAttribute(o),c=Array.from(e.querySelectorAll(a)),u=c.filter(d)[0],h=null==u?void 0:u.getAttribute("class"),m=null===(i=null==u?void 0:u.parentElement)||void 0===i?void 0:i.getAttribute("class"),g=c.filter((e=>!d(e)))[0],b=null==g?void 0:g.getAttribute("class"),p=null===(s=null==g?void 0:g.parentElement)||void 0===s?void 0:s.getAttribute("class");if(!r){n.innerHTML=`\x3c!-- github-file-${this.id}-created-button --\x3e`,n.id=l,n.className=null!=p?p:"";const e=n.querySelector(a),i=e=>{var t;e.setAttribute(o,"true"),h&&e.setAttribute("class",h),m&&(null===(t=e.parentElement)||void 0===t||t.setAttribute("class",m))},s=e=>{var t;e.setAttribute(o,"false"),b&&e.setAttribute("class",b),m&&(null===(t=e.parentElement)||void 0===t||t.setAttribute("class",m))};n.addEventListener("click",(l=>{this.showRendered(t)(l),c.forEach(s),e&&i(e)})),c.forEach((l=>{l.addEventListener("click",(r=>{this.showSource(t)(r),i(l),e&&s(e)}))}))}return n}getFrameElem(e){const t=`${this.frameTagName}.${this.featureClass}`;return(0,l.selectDOM)(t,null!=e?e:document.body)}frameElement(e,t){var i;const s=this.getFrameElem(t);return(0,l.createElement)({attributes:Object.assign({class:this.featureClass,style:(0,l.createElementStyle)(Object.assign({visibility:null!==(i=null==s?void 0:s.style.visibility)&&void 0!==i?i:"hidden"},this.frameStyle))},e),tagName:this.frameTagName,reuse:this.getFrameElem(t)})}addButtonsToFileHeaderActions(e,t){var i;const s=`.BtnGroup.${this.featureClass}`;if((0,l.selectExists)(s,e))return void(null===(i=(0,l.selectDOM)(s,e))||void 0===i||i.childNodes.forEach((e=>{this.updateToggle(e,t)})));const n=(0,r.isPRFiles)()||(0,r.isCommit)()||(0,r.isCompare)();n&&(e.style.alignItems="center"),e.insertBefore(n?this.viewerButtonToggleGroup({frameElem:t,isFileList:n}):this.fileViewerButtonToggle({actionsElem:e,frameElem:t}),e.firstChild)}addFrameToFileBody(e,t,i){return s(this,void 0,void 0,(function*(){if(i&&!(0,l.selectExists)(".js-blob-wrapper",e))return;const s={"data-filepath":t,src:`https://rawgit.com/${this.pathToFile(t)}`,srcDoc:yield this.prepareHTML(yield this.getFileContent(t),t)},r=this.frameElement(s,e);return e.style.position="relative",(0,l.observeEl)(e,(()=>{e.lastElementChild!==r&&e.appendChild(r)}),{childList:!0,subtree:!0}),r}))}extendHtmlFileDetailsElements(e){return()=>Promise.all((0,l.selectAll)(".file.Details").map((t=>s(this,void 0,void 0,(function*(){const i=(0,l.selectOrThrow)(".file-header",t);if(!i.dataset.path)return;const s=`${e}/${i.dataset.path}`;if(this.isSupportedFile(s))try{const e=yield this.addFrameToFileBody((0,l.selectOrThrow)(".js-file-content",t),s,!0);if(!e)return;this.addButtonsToFileHeaderActions((0,l.selectOrThrow)(".file-actions>.d-flex",i),e)}catch(e){console.error(e)}})))))}initDiff(e){if(!e)return;const t=this.extendHtmlFileDetailsElements(e);(0,l.observeEl)("#files",t,{childList:!0,subtree:!0})}initCommit(){this.initDiff((0,r.getCommitSha)())}initCompare(){this.initDiff((0,r.getCompareHeadSha)())}initPRFiles(){var e;this.initDiff(null===(e=(0,l.selectDOM)(".js-reviews-container #head_sha"))||void 0===e?void 0:e.value)}initSingleFile(){return s(this,void 0,void 0,(function*(){const e=(0,r.getRepoPath)().replace("blob/","");if(!this.isSupportedFile(e)){const e=this.getFrameElem();return void(e&&(e.style.visibility="hidden"))}const t=yield this.addFrameToFileBody(yield(0,l.selectOrReject)("section[aria-labelledby='file-name-id']"),e,!1);t&&this.addButtonsToFileHeaderActions(yield(0,l.selectOrReject)("ul[aria-label='File view']"),t)}))}initFeature(){const e=(0,r.isPRFiles)()&&this.initPRFiles(),t=(0,r.isSingleFile)()&&this.initSingleFile(),i=(0,r.isCommit)()&&this.initCommit(),s=(0,r.isCompare)()&&this.initCompare();return Promise.all([e,t,i,s]).then((e=>e.some(Boolean)))}}}}]); \ No newline at end of file diff --git a/lib/github.js b/lib/github.js index cc951957..449c8410 100644 --- a/lib/github.js +++ b/lib/github.js @@ -1 +1 @@ -"use strict";(self.webpackChunkoh_my_scripts=self.webpackChunkoh_my_scripts||[]).push([[830],{4337:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.isPRFiles=t.isSingleFile=t.isCompare=t.isCommit=t.getCompareHeadSha=t.getCommitSha=t.getRepoPath=t.getUserRepo=t.getCleanPathname=t.githubApi=void 0;const i=n(9897),o=n(7594),s="github.com"===location.hostname?"https://api.github.com/":`${location.origin}/api/v3/`,r="compare?/(.{1,40})\\.{3}(.{1,40})",a="commits?/[0-9a-f]{5,40}",c="^pull/\\d+",u=i.ns`GITHUB_TOKEN`;class l extends Error{constructor(...e){super(e.join("\n"))}}function p(){return window.localStorage.getItem(u)}function h(){return location.pathname.replace(/^[/]|[/]$/g,"")}function g(){return h().split("/").slice(2).join("/")}t.githubApi={v3:function(e,t={accept404:!1}){const n=p();return(0,o.request)(s+e,{headers:Object.assign({Accept:"application/vnd.github.v3+json","User-Agent":i.ns`user-script`},n?{Authorization:`token ${n}`}:{})}).then((function(e){var n;return null===(n=e.text)||void 0===n?void 0:n.call(e).then((function(n){const i=n.length>0?JSON.parse(n):{status:e.status};if(e.ok||!0===t.accept404&&404===e.status)return i;throw function(e){return"string"==typeof e.message&&e.message.includes("API rate limit exceeded")?new l("Rate limit exceeded.",p()?"It may be time for a walk!":"Set your token in the options or take a walk!"," 🍃 🌞"):"Bad credentials"===e.message?new l("The token seems to be incorrect or expired. Update it in the options."):new l("Unable to fetch.",p()?"Ensure that your token has access to this repo.":"Maybe adding a token in the options will fix this issue.",JSON.stringify(e,void 0,"\t"))}(i)}))}))}},t.getCleanPathname=h,t.getUserRepo=function(){return h().split("/").slice(0,2).join("/")},t.getRepoPath=g,t.getCommitSha=function(){const e=g().match(a);if(e)return e[0].split("/")[1]},t.getCompareHeadSha=function(){var e;return null===(e=function(){const e=g().match(r);if(e)return e.slice(1,3)}())||void 0===e?void 0:e[1]},t.isCommit=function(){return new RegExp(`^${a}`).test(g())||new RegExp(`${c}/${a}`).test(g())},t.isCompare=function(){return new RegExp(r).test(g())},t.isSingleFile=function(){return/^blob\//.test(g())},t.isPRFiles=function(){return new RegExp(`${c}/files`).test(g())}}}]); \ No newline at end of file +"use strict";(self.webpackChunkoh_my_scripts=self.webpackChunkoh_my_scripts||[]).push([[266],{6116:(t,e,n)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.githubApi=void 0,e.getCleanPathname=h,e.getUserRepo=function(){return h().split("/").slice(0,2).join("/")},e.getRepoPath=g,e.getCommitSha=function(){const t=g().match(a);return t?t[0].split("/")[1]:void 0},e.getCompareHeadSha=function(){var t;return null===(t=function(){const t=g().match(r);return t?t.slice(1,3):void 0}())||void 0===t?void 0:t[1]},e.isCommit=function(){return new RegExp(`^${a}`).test(g())||new RegExp(`${c}/${a}`).test(g())},e.isCompare=function(){return new RegExp(r).test(g())},e.isSingleFile=function(){return/^blob\//.test(g())},e.isPRFiles=function(){return new RegExp(`${c}/files`).test(g())};const i=n(2944),o=n(8730),s="github.com"===location.hostname?"https://api.github.com/":`${location.origin}/api/v3/`,r="compare?/(.{1,40})\\.{3}(.{1,40})",a="commits?/[0-9a-f]{5,40}",c="^pull/\\d+",u=i.ns`GITHUB_TOKEN`;class l extends Error{constructor(...t){super(t.join("\n"))}}function p(){return window.localStorage.getItem(u)}function h(){return location.pathname.replace(/^[/]|[/]$/g,"")}function g(){return h().split("/").slice(2).join("/")}e.githubApi={v3:function(t,e={accept404:!1}){const n=p();return(0,o.request)(s+t,{headers:Object.assign({Accept:"application/vnd.github.v3+json","User-Agent":i.ns`user-script`},n?{Authorization:`token ${n}`}:{})}).then((function(t){var n;return null===(n=t.text)||void 0===n?void 0:n.call(t).then((function(n){const i=n.length>0?JSON.parse(n):{status:t.status};if(t.ok||!0===e.accept404&&404===t.status)return i;throw function(t){return"string"==typeof t.message&&t.message.includes("API rate limit exceeded")?new l("Rate limit exceeded.",p()?"It may be time for a walk!":"Set your token in the options or take a walk!"," 🍃 🌞"):"Bad credentials"===t.message?new l("The token seems to be incorrect or expired. Update it in the options."):new l("Unable to fetch.",p()?"Ensure that your token has access to this repo.":"Maybe adding a token in the options will fix this issue.",JSON.stringify(t,void 0,"\t"))}(i)}))}))}}}}]); \ No newline at end of file diff --git a/lib/interval.js b/lib/interval.js index b50e5078..a9413a67 100644 --- a/lib/interval.js +++ b/lib/interval.js @@ -1 +1 @@ -"use strict";(self.webpackChunkoh_my_scripts=self.webpackChunkoh_my_scripts||[]).push([[382],{3149:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.doEvery=void 0,t.doEvery=function({condition:e,callback:t,intervalMs:c=300}){let o;const s=()=>{e()&&t(),o=setTimeout(s,c)};return s(),{cancel:()=>clearTimeout(o)}}}}]); \ No newline at end of file +"use strict";(self.webpackChunkoh_my_scripts=self.webpackChunkoh_my_scripts||[]).push([[52],{8594:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.doEvery=function({condition:e,callback:t,intervalMs:c=300}){let s;const n=()=>{e()&&t(),s=setTimeout(n,c)};return n(),{cancel:()=>clearTimeout(s)}}}}]); \ No newline at end of file diff --git a/lib/ns.js b/lib/ns.js index 95845aee..991f3221 100644 --- a/lib/ns.js +++ b/lib/ns.js @@ -1 +1 @@ -"use strict";(self.webpackChunkoh_my_scripts=self.webpackChunkoh_my_scripts||[]).push([[218],{9897:(s,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.ns=void 0,e.ns=function(s){return`iamogbz/oh-my-scripts/${s}`}}}]); \ No newline at end of file +"use strict";(self.webpackChunkoh_my_scripts=self.webpackChunkoh_my_scripts||[]).push([[510],{2944:(e,s)=>{Object.defineProperty(s,"__esModule",{value:!0}),s.ns=function(e){return`iamogbz/oh-my-scripts/${e}`}}}]); \ No newline at end of file diff --git a/lib/paths.js b/lib/paths.js index c4c1e83d..9ddb87f9 100644 --- a/lib/paths.js +++ b/lib/paths.js @@ -1 +1 @@ -"use strict";(self.webpackChunkoh_my_scripts=self.webpackChunkoh_my_scripts||[]).push([[270],{2041:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.fileDirname=t.normalisePath=t.isAbsolutePath=t.getFileType=void 0,t.getFileType=function(e,t=1){var n;const i=null===(n=e.split("/").slice(-1).pop())||void 0===n?void 0:n.split(".");if(!i||i.length<2)return"";const[,...s]=i;return t?s.slice(Math.max(s.length-t,0)).join("."):s.join(".")},t.isAbsolutePath=function(e){return e&&/^(?:[a-z]+:)?\/\//i.test(e)},t.normalisePath=function(e){try{return new URL(e).href}catch(t){const n="x://";return new URL(`${n}${e}`).href.substr(n.length)}},t.fileDirname=function(e){return e.substring(0,e.lastIndexOf("/"))}}}]); \ No newline at end of file +"use strict";(self.webpackChunkoh_my_scripts=self.webpackChunkoh_my_scripts||[]).push([[977],{7131:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getFileType=function(e,t=1){var n;const r=null===(n=e.split("/").slice(-1).pop())||void 0===n?void 0:n.split(".");if(!r||r.length<2)return"";const[,...s]=r;return t?s.slice(Math.max(s.length-t,0)).join("."):s.join(".")},t.isAbsolutePath=function(e){return e&&/^(?:[a-z]+:)?\/\//i.test(e)},t.normalisePath=function(e){try{return new URL(e).href}catch(t){console.error(t);const n="x://";return new URL(`${n}${e}`).href.substr(n.length)}},t.fileDirname=function(e){return e.substring(0,e.lastIndexOf("/"))}}}]); \ No newline at end of file diff --git a/lib/request.js b/lib/request.js index d5499b63..0ec0e5e8 100644 --- a/lib/request.js +++ b/lib/request.js @@ -1 +1 @@ -"use strict";(self.webpackChunkoh_my_scripts=self.webpackChunkoh_my_scripts||[]).push([[903],{7594:(e,s)=>{Object.defineProperty(s,"__esModule",{value:!0}),s.request=void 0,s.request=function(e,s){return window.GM_xmlhttpRequest?new Promise(((t,o)=>{const r=Object.assign({onabort:o,onerror:o,onload:e=>{t({blob:()=>Promise.resolve(new Blob([e.response])),headers:e.responseHeaders,json:()=>Promise.resolve(JSON.parse(e.responseText)),ok:e.status>=200&&e.status<300,status:e.status,statusText:e.statusText,text:()=>Promise.resolve(e.responseText),url:e.finalUrl})},ontimeout:o,url:e},s);window.GM_xmlhttpRequest(r)})):fetch(e,s)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkoh_my_scripts=self.webpackChunkoh_my_scripts||[]).push([[898],{8730:(e,s)=>{Object.defineProperty(s,"__esModule",{value:!0}),s.request=function(e,s){return window.GM_xmlhttpRequest?new Promise(((t,o)=>{const r=Object.assign({onabort:o,onerror:o,onload:e=>{t({blob:()=>Promise.resolve(new Blob([e.response])),headers:e.responseHeaders,json:()=>Promise.resolve(JSON.parse(e.responseText)),ok:e.status>=200&&e.status<300,status:e.status,statusText:e.statusText,text:()=>Promise.resolve(e.responseText),url:e.finalUrl})},ontimeout:o,url:e},s);window.GM_xmlhttpRequest(r)})):fetch(e,s)}}}]); \ No newline at end of file diff --git a/no-window-open.user.js b/no-window-open.user.js index fe567971..b28a98fc 100644 --- a/no-window-open.user.js +++ b/no-window-open.user.js @@ -1,18 +1,18 @@ // ==UserScript== // @name No Window Open // @description Blocks window open -// @version 1.3.0 +// @version 1.4.0 // @author iamogbz // @homepage https://github.com/iamogbz/oh-my-scripts // @supportURL https://github.com/iamogbz/oh-my-scripts/issues // @match *://*/* -// @downloadURL https://github.com/iamogbz/oh-my-scripts/raw/1.3.0/no-window-open.user.js +// @downloadURL https://github.com/iamogbz/oh-my-scripts/raw/1.4.0/no-window-open.user.js // @grant none // @icon https://github.com/iamogbz/oh-my-scripts/raw/main/assets/monkey_128.png // @namespace iamogbz/oh-my-scripts -// @require https://github.com/iamogbz/oh-my-scripts/raw/1.3.0/lib/dom.js +// @require https://github.com/iamogbz/oh-my-scripts/raw/1.4.0/lib/dom.js // @require https://raw.githubusercontent.com/Martii/UserScripts/d8d8829/lib/GM_setStyle/GM_setStyle.js // @updateURL https://github.com/iamogbz/oh-my-scripts/raw/gh-pages/no-window-open.user.js // ==/UserScript== -(()=>{"use strict";var e,n={884:(e,n,t)=>{const r=t(6193);!function(){function e(e){return`iamogbz-no-window-open-${e}`}const n=1e4,t=e`popup-element`,o=e`popup-element-link`,i=e`popup-element-close`,a=e`popup-element-visible`,s=`\n#${t} {\n align-items: center;\n background-color: #241200EE;\n border-radius: 4px;\n bottom: 8px;\n box-shadow: #00000032 1px 1px 8px;\n color: white;\n display: flex;\n flex-flow: column;\n font-size: 0.8em;\n overflow: hidden;\n padding: 8px;\n position: fixed;\n right: -264px;\n text-align: center;\n transition: right 0.3s ease;\n width: 248px;\n}\n\n#${t}.${a} {\n right: 8px;\n z-index: ${Number.MAX_SAFE_INTEGER};\n}\n\n#${t} #${i} {\n background-color: #8d0303EE;\n border-radius: 2px;\n border: none;\n color: white;\n cursor: pointer;\n font-size: 0.8em;\n margin-top: 8px;\n padding: 4px 6px;\n width: 100%;\n}\n\n#${t} #${o} {\n background-color: #0366d6AA;\n border-radius: 2px;\n color: white;\n cursor: pointer;\n margin-top: 4px;\n padding: 2px 6px;\n word-break: break-all;\n}\n`,p="This page just attempted to open a url.\nClick on it below to proceed with navigation.";let l,c;function d(){const e=document.getElementById(t)||(0,r.createElement)({attributes:{id:t},children:[{children:[p],tagName:"div"},{attributes:{id:o,target:"_blank",referrer:"noreferrer"},tagName:"a"},{attributes:{id:i},children:["Dismiss"],events:{click:h},tagName:"button"}],events:{mouseover:m},tagName:"div"});return document.body.appendChild(e),e}function u(){return d().querySelector(`#${o}`)}function f(e){l=e,d(),u().setAttribute("href",e),u().innerHTML=e}function m(){d().classList.add(a),clearTimeout(c),c=setTimeout(h,n)}function h(){d().classList.remove(a)}window.GM_setStyle({data:s}),window.open=function(e){return console.log(`window.open(${e})`),f(e),clearTimeout(c),setTimeout(m,300),{get location(){return{assign:f,close:h,replace:f,get href(){return l},set href(e){f(e)}}},set location(e){e&&("string"==typeof e?f(e):e.href&&f(e.href))}}}}()}},t={};function r(e){var o=t[e];if(void 0!==o)return o.exports;var i=t[e]={exports:{}};return n[e].call(i.exports,i,i.exports,r),i.exports}r.m=n,e=[],r.O=(n,t,o,i)=>{if(!t){var a=1/0;for(c=0;c=i)&&Object.keys(r.O).every((e=>r.O[e](t[p])))?t.splice(p--,1):(s=!1,i0&&e[c-1][2]>i;c--)e[c]=e[c-1];e[c]=[t,o,i]},r.o=(e,n)=>Object.prototype.hasOwnProperty.call(e,n),(()=>{var e={508:0};r.O.j=n=>0===e[n];var n=(n,t)=>{var o,i,[a,s,p]=t,l=0;if(a.some((n=>0!==e[n]))){for(o in s)r.o(s,o)&&(r.m[o]=s[o]);if(p)var c=p(r)}for(n&&n(t);lr(884)));o=r.O(o)})(); \ No newline at end of file +(()=>{"use strict";var e,n={7303:(e,n,t)=>{const r=t(9091);!function(){function e(e){return`iamogbz-no-window-open-${e}`}const n=1e4,t=e`popup-element`,o=e`popup-element-link`,i=e`popup-element-close`,a=e`popup-element-visible`,s=`\n#${t} {\n align-items: center;\n background-color: #241200EE;\n border-radius: 4px;\n bottom: 8px;\n box-shadow: #00000032 1px 1px 8px;\n color: white;\n display: flex;\n flex-flow: column;\n font-size: 0.8em;\n overflow: hidden;\n padding: 8px;\n position: fixed;\n right: -264px;\n text-align: center;\n transition: right 0.3s ease;\n width: 248px;\n}\n\n#${t}.${a} {\n right: 8px;\n z-index: ${Number.MAX_SAFE_INTEGER};\n}\n\n#${t} #${i} {\n background-color: #8d0303EE;\n border-radius: 2px;\n border: none;\n color: white;\n cursor: pointer;\n font-size: 0.8em;\n margin-top: 8px;\n padding: 4px 6px;\n width: 100%;\n}\n\n#${t} #${o} {\n background-color: #0366d6AA;\n border-radius: 2px;\n color: white;\n cursor: pointer;\n margin-top: 4px;\n padding: 2px 6px;\n word-break: break-all;\n}\n`,p="This page just attempted to open a url.\nClick on it below to proceed with navigation.";let l,c;function d(){const e=document.getElementById(t)||(0,r.createElement)({attributes:{id:t},children:[{children:[p],tagName:"div"},{attributes:{id:o,target:"_blank",referrer:"noreferrer"},tagName:"a"},{attributes:{id:i},children:["Dismiss"],events:{click:h},tagName:"button"}],events:{mouseover:m},tagName:"div"});return document.body.appendChild(e),e}function u(){return d().querySelector(`#${o}`)}function f(e){l=e,d(),u().setAttribute("href",e),u().innerHTML=e}function m(){d().classList.add(a),clearTimeout(c),c=setTimeout(h,n)}function h(){d().classList.remove(a)}window.GM_setStyle({data:s}),window.open=function(e){return console.log(`window.open(${e})`),f(e),clearTimeout(c),setTimeout(m,300),{get location(){return{assign:f,close:h,replace:f,get href(){return l},set href(e){f(e)}}},set location(e){e&&("string"==typeof e?f(e):e.href&&f(e.href))}}}}()}},t={};function r(e){var o=t[e];if(void 0!==o)return o.exports;var i=t[e]={exports:{}};return n[e].call(i.exports,i,i.exports,r),i.exports}r.m=n,e=[],r.O=(n,t,o,i)=>{if(!t){var a=1/0;for(c=0;c=i)&&Object.keys(r.O).every((e=>r.O[e](t[p])))?t.splice(p--,1):(s=!1,i0&&e[c-1][2]>i;c--)e[c]=e[c-1];e[c]=[t,o,i]},r.o=(e,n)=>Object.prototype.hasOwnProperty.call(e,n),(()=>{var e={9:0};r.O.j=n=>0===e[n];var n=(n,t)=>{var o,i,[a,s,p]=t,l=0;if(a.some((n=>0!==e[n]))){for(o in s)r.o(s,o)&&(r.m[o]=s[o]);if(p)var c=p(r)}for(n&&n(t);lr(7303)));o=r.O(o)})(); \ No newline at end of file