From 3b31d4881abde11a6584444d65e31aee393a7602 Mon Sep 17 00:00:00 2001 From: ChunkyProgrammer <78101139+ChunkyProgrammer@users.noreply.github.com> Date: Tue, 19 Dec 2023 18:27:09 -0500 Subject: [PATCH] Add Polyfills for improved IE support --- assets/js/polyfills/UrlPolyfill.js | 2 ++ assets/js/polyfills/locationOriginPolyfill.js | 23 +++++++++++++++++++ src/invidious/views/embed.ecr | 2 ++ src/invidious/views/licenses.ecr | 23 +++++++++++++++++++ src/invidious/views/template.ecr | 2 ++ 5 files changed, 52 insertions(+) create mode 100644 assets/js/polyfills/UrlPolyfill.js create mode 100644 assets/js/polyfills/locationOriginPolyfill.js diff --git a/assets/js/polyfills/UrlPolyfill.js b/assets/js/polyfills/UrlPolyfill.js new file mode 100644 index 00000000..f589589d --- /dev/null +++ b/assets/js/polyfills/UrlPolyfill.js @@ -0,0 +1,2 @@ +/*! (C) Valentin Richard - Mit Style License */ +(function(t){var e=function(){try{return!!Symbol.iterator}catch(e){return false}};var r=e();var n=function(t){var e={next:function(){var e=t.shift();return{done:e===void 0,value:e}}};if(r){e[Symbol.iterator]=function(){return e}}return e};var i=function(e){return encodeURIComponent(e).replace(/%20/g,"+")};var o=function(e){return decodeURIComponent(String(e).replace(/\+/g," "))};var a=function(){var a=function(e){Object.defineProperty(this,"_entries",{writable:true,value:{}});var t=typeof e;if(t==="undefined"){}else if(t==="string"){if(e!==""){this._fromString(e)}}else if(e instanceof a){var r=this;e.forEach(function(e,t){r.append(t,e)})}else if(e!==null&&t==="object"){if(Object.prototype.toString.call(e)==="[object Array]"){for(var n=0;nt[0]){return+1}else{return 0}});if(r._entries){r._entries={}}for(var e=0;e1?o(i[1]):"")}}})}})(typeof global!=="undefined"?global:typeof window!=="undefined"?window:typeof self!=="undefined"?self:this);(function(u){var e=function(){try{var e=new u.URL("b","http://a");e.pathname="c d";return e.href==="http://a/c%20d"&&e.searchParams}catch(e){return false}};var t=function(){var t=u.URL;var e=function(e,t){if(typeof e!=="string")e=String(e);if(t&&typeof t!=="string")t=String(t);var r=document,n;if(t&&(u.location===void 0||t!==u.location.href)){t=t.toLowerCase();r=document.implementation.createHTMLDocument("");n=r.createElement("base");n.href=t;r.head.appendChild(n);try{if(n.href.indexOf(t)!==0)throw new Error(n.href)}catch(e){throw new Error("URL unable to set base "+t+" due to "+e)}}var i=r.createElement("a");i.href=e;if(n){r.body.appendChild(i);i.href=i.href}var o=r.createElement("input");o.type="url";o.value=e;if(i.protocol===":"||!/:/.test(i.href)||!o.checkValidity()&&!t){throw new TypeError("Invalid URL")}Object.defineProperty(this,"_anchorElement",{value:i});var a=new u.URLSearchParams(this.search);var s=true;var f=true;var c=this;["append","delete","set"].forEach(function(e){var t=a[e];a[e]=function(){t.apply(a,arguments);if(s){f=false;c.search=a.toString();f=true}}});Object.defineProperty(this,"searchParams",{value:a,enumerable:true});var h=void 0;Object.defineProperty(this,"_updateSearchParams",{enumerable:false,configurable:false,writable:false,value:function(){if(this.search!==h){h=this.search;if(f){s=false;this.searchParams._fromString(this.search);s=true}}}})};var r=e.prototype;var n=function(t){Object.defineProperty(r,t,{get:function(){return this._anchorElement[t]},set:function(e){this._anchorElement[t]=e},enumerable:true})};["hash","host","hostname","port","protocol"].forEach(function(e){n(e)});Object.defineProperty(r,"search",{get:function(){return this._anchorElement["search"]},set:function(e){this._anchorElement["search"]=e;this._updateSearchParams()},enumerable:true});Object.defineProperties(r,{toString:{get:function(){var e=this;return function(){return e.href}}},href:{get:function(){return this._anchorElement.href.replace(/\?$/,"")},set:function(e){this._anchorElement.href=e;this._updateSearchParams()},enumerable:true},pathname:{get:function(){return this._anchorElement.pathname.replace(/(^\/?)/,"/")},set:function(e){this._anchorElement.pathname=e},enumerable:true},origin:{get:function(){var e={"http:":80,"https:":443,"ftp:":21}[this._anchorElement.protocol];var t=this._anchorElement.port!=e&&this._anchorElement.port!=="";return this._anchorElement.protocol+"//"+this._anchorElement.hostname+(t?":"+this._anchorElement.port:"")},enumerable:true},password:{get:function(){return""},set:function(e){},enumerable:true},username:{get:function(){return""},set:function(e){},enumerable:true}});e.createObjectURL=function(e){return t.createObjectURL.apply(t,arguments)};e.revokeObjectURL=function(e){return t.revokeObjectURL.apply(t,arguments)};u.URL=e};if(!e()){t()}if(u.location!==void 0&&!("origin"in u.location)){var r=function(){return u.location.protocol+"//"+u.location.hostname+(u.location.port?":"+u.location.port:"")};try{Object.defineProperty(u.location,"origin",{get:r,enumerable:true})}catch(e){setInterval(function(){u.location.origin=r()},100)}}})(typeof global!=="undefined"?global:typeof window!=="undefined"?window:typeof self!=="undefined"?self:this); \ No newline at end of file diff --git a/assets/js/polyfills/locationOriginPolyfill.js b/assets/js/polyfills/locationOriginPolyfill.js new file mode 100644 index 00000000..0135845b --- /dev/null +++ b/assets/js/polyfills/locationOriginPolyfill.js @@ -0,0 +1,23 @@ +/*! (C) 2014 - 2015 Shinnosuke Watanabe - Mit Style License */ +(function() { + 'use strict'; + var loc, value; + + loc = window.location; + + if (loc.origin) { + return; + } + + value = loc.protocol + '//' + loc.hostname + (loc.port ? ':' + loc.port : ''); + + try { + Object.defineProperty(loc, 'origin', { + value: value, + enumerable: true + }); + } catch (_error) { + loc.origin = value; + } + +}).call(this); diff --git a/src/invidious/views/embed.ecr b/src/invidious/views/embed.ecr index 1bf5cc3e..485c0256 100644 --- a/src/invidious/views/embed.ecr +++ b/src/invidious/views/embed.ecr @@ -11,6 +11,8 @@ <%= HTML.escape(video.title) %> - Invidious + + diff --git a/src/invidious/views/licenses.ecr b/src/invidious/views/licenses.ecr index 667cfa37..88108051 100644 --- a/src/invidious/views/licenses.ecr +++ b/src/invidious/views/licenses.ecr @@ -302,6 +302,29 @@ <%= translate(locale, "source") %> + + + + UrlPolyfill.js + + + Expat + + + <%= translate(locale, "source") %> + + + + + locationOriginPolyfill.js + + + Expat + + + <%= translate(locale, "source") %> + + diff --git a/src/invidious/views/template.ecr b/src/invidious/views/template.ecr index 77265679..f84d875f 100644 --- a/src/invidious/views/template.ecr +++ b/src/invidious/views/template.ecr @@ -17,6 +17,8 @@ + +