Perplexity Force Writing Mode

Force "writing mode" on perplexity

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

You will need to install an extension such as Tampermonkey to install this script.

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         Perplexity Force Writing Mode
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Force "writing mode" on perplexity
// @author       Lugia19
// @match        https://www.perplexity.ai/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function () {
'use strict';

// Store the original fetch function
const originalFetch = window.fetch;

// Override the fetch function
window.fetch = async function (...args) {
const url = args[0];
let urlString = '';

// Handle different types of URL arguments
if (typeof url === 'string') {
urlString = url;
} else if (url instanceof URL) {
urlString = url.href;
} else if (url instanceof Request) {
urlString = url.url;
}

// Check if this is a request to the target endpoint
if (urlString.includes('https://www.perplexity.ai/rest/sse/perplexity_ask')) {
try {
// Clone the request to avoid modifying the original
let request = args[1] || {};

// If there's a body, parse and modify it
if (request.body) {
const body = JSON.parse(request.body);

// Force the search_focus to be "writing"
if (body.params) {
body.params.search_focus = "writing";
body.params.local_search_enabled = false;
console.log("Forced search_focus to 'writing'");
}

// Create a new request with the modified body
const newRequest = {
...request,
body: JSON.stringify(body)
};

// Replace the original request with our modified one
args[1] = newRequest;
}
} catch (error) {
console.error("Error in fetch monkeypatch:", error);
}
}

// Call the original fetch with possibly modified arguments
return originalFetch.apply(this, args);
};

console.log("Perplexity.ai Force Writing Focus userscript loaded");
})();