Bing: Strict Mode Always Off

Set Bing strict mode to off, always.

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください。
// ==UserScript==
// @name        Bing: Strict Mode Always Off
// @namespace   Violentmonkey Scripts
// @match       *://*.bing.com/*
// @grant       none
// @version     1.1
// @author      Chaewon
// @license     Unlicense
// @icon        https://www.bing.com/favicon.ico
// @description Set Bing strict mode to off, always.
// ==/UserScript==

(function () {
	"use strict";
	/**
	 * Retrieve the value of a specific cookie by name.
	 * @param {string} name - The name of the cookie.
	 * @returns {string|null} The value of the cookie or null if not found.
	 */
	function getCookie(name) {
		const nameEQ = name + "=";
		const cookies = document.cookie.split(";");
		for (let i = 0; i < cookies.length; i++) {
			let cookie = cookies[i].trim();
			if (cookie.indexOf(nameEQ) === 0) {
				return cookie.substring(nameEQ.length, cookie.length);
			}
		}
		return null;
	}

	/**
	 * Set a cookie with a specific name, value, and expiry.
	 * @param {string} name - The name of the cookie.
	 * @param {string} value - The value of the cookie.
	 * @param {number} days - The number of days until the cookie expires.
	 */
	function setCookie(name, value, days) {
		const expires = days
			? "; expires=" + new Date(Date.now() + days * 864e5).toUTCString()
			: "";
		document.cookie = name + "=" + value + expires + "; path=/; Secure";
	}

	let bingCookie = getCookie("SRCHHPGUSR");
	if (bingCookie) {
		let params = new URLSearchParams(bingCookie.replace(/;/g, "&"));
		if (params.has("ADLT")) {
			const adltValue = params.get("ADLT");
			if (adltValue === "OFF") {
				console.log("Cookie already set to ADLT=OFF");
				return;
			} else {
				params.set("ADLT", "OFF");
				let updatedCookie = params.toString();
				console.log("Updated cookie: " + updatedCookie);
				setCookie("SRCHHPGUSR", updatedCookie, 365);
				location.reload();
			}
		} else {
			params.set("ADLT", "OFF");
			let updatedCookie = params.toString();
			console.log("Updated cookie: " + updatedCookie);
			setCookie("SRCHHPGUSR", updatedCookie, 365);
			location.reload();
		}
	} else {
		console.log("Cookie not found.");
	}
})();