PWAs Anywhere

Allow installing any webpage as a progressive web app

目前為 2024-03-24 提交的版本,檢視 最新版本

// ==UserScript==
// @name        PWAs Anywhere
// @namespace   https://www.octt.eu.org/
// @match       *://*/*
// @grant       none
// @version     1.0.0
// @author      OctoSpacc
// @license     ISC
// @description Allow installing any webpage as a progressive web app
// @run-at      document-idle
// ==/UserScript==

if (!document.querySelector('link[rel="manifest"]')) {
  var descElem = document.querySelector('meta[name="description"]');
  var iconElem = (document.querySelector('link[rel~="apple-touch-icon"]') || document.querySelector('link[rel~="icon"]'));
  var manifestElem = document.createElement('link');
  manifestElem.rel = 'manifest';
  manifestElem.href = ('data:application/manifest+json;utf8,' + encodeURIComponent(JSON.stringify({
    name: (document.title || location.href),
    description: (descElem && descElem.content),
    start_url: location.href,
    scope: location.href,
    display: "standalone",
    // background_color: getComputedStyle(document.body).backgroundColor,
    icons: [
      {
        src: ((iconElem && iconElem.href) || '/favicon.ico'),
        // type: (iconElem ? (iconElem.type || 'image/png') : 'image/x-icon'),
        sizes: "any",
        purpose: "any",
      },
    ],
  })));
  document.head.appendChild(manifestElem);
}