Greasy Fork

Greasy Fork is available in English.

iCloud PWA App Icons

iCloud favicon/icons for the apps of icloud and PWAs

目前为 2022-12-12 提交的版本,查看 最新版本

// ==UserScript==
// @name         iCloud PWA App Icons
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  iCloud favicon/icons for the apps of icloud and PWAs
// @author       http://greasyfork.icu/en/users/996660-olgro
// @match        https://www.icloud.com/**
// @icon         https://www.google.com/s2/favicons?sz=64&domain=icloud.com
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    function iconUrl(id) {
        return 'https://www.icloud.com/system/icloud.com/2303Hotfix61/en-us/' + id + '.png';
    }

    const appIcons = {
        'find': iconUrl('32f2db22e40a7765c151f4d947c2be50'),
        'notes': iconUrl('ddc3380f93d44a376c586796bb7c16a7'),
        'mail': iconUrl('a6e032ae59d1fd9d47ac97d7b2e2a3af'),
        'contacts': iconUrl('4b1d90456b68a8d4d4b91adb39e60b70'),
        'photos': iconUrl('1c11f0fa22d4e93f8dc179b8ff84791d'),
        'drive': iconUrl('dccb81ba3f0f63e9a50c162007f59c4a'),
        'reminders': iconUrl('1b5c615b834cbb4d30e0c229e8e099a3'),
        'pages': iconUrl('3c581ce16ec89eedc1d6862e31ccd8b3'),
        'numbers': iconUrl('f5b837094af69a157a6fc7f413e04fb7'),
        'keynote': iconUrl('43f50d5d6df53dc6bddf56d7ceb257d0'),
        'default': '/system/icloud.com/current/static/apple-touch-icon-precomposed.png',
    }

    function changeIcon() {
        console.log('change icon');
        const currentApp = window.location.href.split('/')[3];
        const currentIcon = appIcons[currentApp] ?? appIcons['default'];
        console.log(currentApp, currentIcon);


        // remove icon tags from header
        [...document.head.children].forEach(child => {
            const rel = child.rel;
            if (rel && rel.includes('icon')) {
                document.head.removeChild(child);
            }
        });

        const link = document.createElement('link');
        link.type = 'image/png';
        link.rel = 'shortcut icon';
        link.href = currentIcon;

        //link.href = 'http://fonts.googleapis.com/css?family=Oswald&effect=neon';
        document.head.appendChild(link);
    }

    changeIcon();
    window.addEventListener('locationchange', changeIcon);
    window.addEventListener('popstate', changeIcon);

    (function(history){
        var pushState = history.pushState;
        history.pushState = function(state) {
            setTimeout(() => {
                changeIcon();
            }, 100);
            return pushState.apply(history, arguments);
        };
    })(window.history);
})();