模拟竖屏

由于有些链接用小窗模式的浏览器打开,会提示切换到竖屏,特此模拟竖屏

// ==UserScript==
// @name         模拟竖屏
// @namespace    https://greasyfork.org/zh-CN/scripts/479590
// @supportURL   https://github.com/WhiteSevs/TamperMonkeyScript/issues
// @icon         data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAAAXNSR0IArs4c6QAACnFJREFUeF7tnXnsJUURxz8QFAUUVIzZVfBCTXZXUBajYBQRFQygolF3vYJBUSJHVBJUgkdUDiUYPEA5l1UBZdUV1ws1Hiii8T4AXRX+QDAcMUERISHY32w/Mwzd703P65np95uqZLKb3+vp7qr6TnV1d3X1VhiNWgJbjZp7Yx4DwMhBYAAwAIxcAiNn3yyAAWDkEhg5+2YBDAAjl8DI2TcLsAUA+wMHA88BlgHLC8HF3cCNwE3AZcDlwK9y9q1kALwL2AW4FPhBTqYrda0FjgWe2VH9XVT7JeAMB9orclReKgCuqinlg8B7czBcqePLwKGZ6+yzutOBd87bYIkA0NcoANTpVEBWIQfdADw6R0UD1yHLuN88fSgRAIcBF0SY+hjwjnkYBn4MPHvOOkp6/XjgI207VCIAtgWuBR4XYeoc5xgd0ZLhDwPvmfLuH4Gr/dOyiayvbed8oJXAiinyUIOvAS5u03KJABAfLwMuAh4cYeobwEGJDMvD/1HknWuAtwPfTqyzz+JvA2QBHxBo9A/As4A7UjtUKgDEx/OBS4BHRpj6LfC0BIY3AK8IlP+A+9v7E+oZuujPgWcEOnECcFJq50oGgHiRguWtPz7C2K1TAFJ9ZW/gykAdf3am8ympQhu4vNYptDZQp78BT0ztW6kA2MMvzmiBRl5ubCgQvxLGLI9eX8a7A8I5BNiUKrQCystivS/QjwP8YlHjLpYEgNXA673Cd2/MwZaCb3Do/+yUd37iBLNP7fe/A49JbKeU4qvccPb7QGcEdA0FjakEAEjx8urbevZi9lV+xTDG+F8C5nHuOXRjKXdTMMTTecCbUpobEgA5FD/hVT7C9VMY/xewQ+33TwNHpgirsLLr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4J/JDv4qLtpPUn2QVpqQ0A9PXLCogOcQGQmxaEV+tmQAJtAKBbQBSQoGvic8e5mZJ6lkAbAKiLF/g7g/X/ffw2as9dX+jmdgVuA+4Ymou2AFCwo4IPzwhc/zI0T4vQ/lUeANrHD8X29cZDWwD01sEl2FB1Kf08F8OnvYjByADQn+gVtKFglEkwp6KS5UcNSrkBcDTwCEDn5LSJYQTaZNKZAIVsVTeZdCZBZxMGpZwA2M2FWG+ucKNQJQUt/DfCYcrdfzEhhepIuX4udIeh2kqpI9QH+UgKQNVpJD2KR5yQxn3FIdw5qOZ94zkB8Ckfc6cDkk0o5e6/UH06eRMDQOgCyVAdsXT3sWPeoTpCfOwbcI6v8NfradwvhnICQExt4+LvX+4Vo6NYenaIcLvUAaDxXuFaer7jgzmKUfykI7kBUByD1qHpEjAAjBwhBgADwMglMHL2zQIYAEYugZGzbxbAADByCYycfbMAIwfA/wATa4CfFIX0pAAAAABJRU5ErkJggg==
// @version      2024.1.11
// @description  由于有些链接用小窗模式的浏览器打开,会提示切换到竖屏,特此模拟竖屏
// @author       WhiteSevs
// @license      GPL-3.0-only
// @match        https://eggy.163.com/*
// @match        https://igame.qq.com/*
// @match        https://*.eggygogame.com/*
// @match        https://*.eggy-go.com/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function () {
	if (typeof unsafeWindow === "undefined") {
		if (
			typeof globalThis.unsafeWindow !== "undefined" &&
			globalThis.unsafeWindow != null
		) {
			var unsafeWindow = globalThis.unsafeWindow;
		} else {
			var unsafeWindow = globalThis || window || self;
		}
	}
  /**
   * 油猴环境下就是unsafeWindow,如果不是就是globalThis
   */
  const win = typeof unsafeWindow === "object" ? unsafeWindow : globalThis;

  /**
   * 添加CSS到页面中
   * @param {string} cssText CSS字符串
   */
  const GM_addStyle = function (cssText) {
    if (cssText == null) {
      return;
    }
    if (typeof cssText !== "string") {
      return;
    }
    if (cssText.trim() === "") {
      return;
    }
    let cssNode = document.createElement("style");
    cssNode.setAttribute("type", "text/css");
    cssNode.innerHTML = cssText;
    if (document.head) {
      /* 插入head后 */
      document.head.appendChild(cssNode);
    } else if (document.documentElement.childNodes.length === 0) {
      /* 插入body后 */
      document.documentElement.appendChild(cssNode);
    } else {
      /* 插入head前面 */
      document.documentElement.insertBefore(
        cssNode,
        document.documentElement.childNodes[0]
      );
    }
  };

  /**
   * 配置
   * @typedef {object} verticalScreenWebSiteDetails
   * @property {?string} hostName 匹配的网站hostName,和href任选其一
   * @property {?string} href 匹配的网站href,和hostName任选其一,可正则
   * @property {?string} CSS 竖屏CSS
   */
  /**
   * @type {verticalScreenWebSiteDetails[]}
   */
  const verticalScreenWebSite = [
    {
      hostName: "igame.qq.com",
      CSS: `@charset "UTF-8";@media all and (orientation:landscape){html{width:unset;height:unset;overflow:unset}
            html::before{position:unset;top:unset;left:unset;z-index:unset;width:unset;height:unset;background:unset;content:unset}
            body::after{content:unset;text-align:unset;font-size:unset;color:unset;position:unset;top:unset;left:unset;height:unset;width:unset;margin-top:unset;z-index:unset}
            body::before{content:unset;position:unset;z-index:unset;height:unset;width:unset;left:unset;top:unset;margin:unset;color:unset;background-image:unset;background-repeat:unset;background-position:unset;background-size:unset;-webkit-transform:unset}}`,
    },
  ];

  /**
   * 劫持
   */
  const hijack = {
    /**
     * 劫持window.orientation
     */
    hijackOrientation() {
      Object.defineProperty(win, "orientation", {
        /**
         * 0是正常竖屏
         * 90是倒着的竖屏
         * @returns {number}
         */
        get() {
          console.log("模拟竖屏:window.orientation ===> 0");
          return 0;
        },
      });
    },
  };

  /**
   * 模拟
   */
  const simulation = function () {
    /* 自动劫持 */
    hijack.hijackOrientation();
    for (const webSiteConfig of verticalScreenWebSite) {
      if (
        (typeof webSiteConfig.hostName === "string" &&
          win.location.hostname === webSiteConfig.hostName) ||
        (typeof webSiteConfig.href === "string" &&
          win.location.href.match(webSiteConfig.href))
      ) {
        /* hostname相等|href包含 */
        if (typeof webSiteConfig.CSS === "string") {
          /* 添加额外的CSS */
          GM_addStyle(webSiteConfig.CSS);
          console.log("模拟竖屏:添加自定义CSS");
        }
      }
    }
  };

  /* --------------------入口-------------------- */
  simulation();
  /* --------------------入口-------------------- */
})();