PWAs anywhere mod without options

Allow installing any webpage as a progressive web app

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        PWAs anywhere mod without options
// @match       *://*/*
// @version     1.0.1
// @author      OctoSpacc
// @license     ISC
// @description Allow installing any webpage as a progressive web app
// @run-at      document-idle
// @namespace https://greasyfork.org/users/1381439
// ==/UserScript==

var originalManifest = document.querySelector('link[rel="manifest"]');

function makeManifestElem(href) {
 var manifestElem = document.createElement('link');
 manifestElem.rel = 'manifest';
 manifestElem.href = href;
 return manifestElem;
}

function removeCurrentManifest() {
 var manifestElem = document.querySelector('link[rel="manifest"]');
 if (manifestElem) {
  manifestElem.parentElement.removeChild(manifestElem);
 }
}

function createAndInjectManifest() {
 var iconElem = (document.querySelector('link[rel~="apple-touch-icon"]') || document.querySelector('link[rel~="icon"]'));
 var manifestElem = makeManifestElem('data:application/manifest+json;utf8,' + encodeURIComponent(JSON.stringify({
  name: (document.title || location.href),
  start_url: location.href,
  scope: (location.protocol + '//' + location.hostname + '/'),
  display: "standalone",
  background_color: (getComputedStyle(document.body).backgroundColor || '#000000'),
  theme_color: '#000000',
  icons: [{
   src: ((iconElem && iconElem.href) || (location.href + '/favicon.ico')),
   sizes: "any",
   purpose: "any",
  }, ],
 })));
 document.head.appendChild(manifestElem);
}

if (originalManifest) {
 removeCurrentManifest();
 createAndInjectManifest();
} else {
 createAndInjectManifest();
}