Intent share URL Query string for Pinafore

Recieve "overwrite" value and overwrite compose-box

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name           Intent share URL Query string for Pinafore
// @name:ja        共有URLクエリ文字列 for Pinafore
// @namespace      https://github.com/yzrsng
// @description    Recieve "overwrite" value and overwrite compose-box
// @description:ja overwriteの値を受け取り投稿ボックスを上書きする
// @version        0.1.20240122.1
// @license        CC0-1.0
// @match          *://pinafore.social/?overwrite=*
// @match          *://semaphore.social/?overwrite=*
// @grant          none
// @run-at         document-end
// ==/UserScript==

(function() {
  'use strict';
  const params = (new URL(document.location)).searchParams;
  const textParam = params.get('overwrite');
  if (!textParam) return;
  const currentInstance = localStorage.getItem("store_currentInstance").slice(1,-1);
  if (!currentInstance) return;

  // {"pinafore.social":{"home":{"ts":0,"text":"hoge"}}}
  const oldData = localStorage.getItem("store_composeData");
  const tmpObj = oldData ? JSON.parse(oldData) : {};
  if (!tmpObj[currentInstance]) {
    tmpObj[currentInstance] = {};
    tmpObj[currentInstance].home = {};
    tmpObj[currentInstance].home.text = '';
  } else if (!tmpObj[currentInstance].home) {
    tmpObj[currentInstance].home = {};
    tmpObj[currentInstance].home.text = '';
  } else if (!tmpObj[currentInstance].home.text) {
    tmpObj[currentInstance].home.text = '';
  }
  if (tmpObj[currentInstance].home.text === textParam) return;
  tmpObj[currentInstance].home.text = textParam;
  const date = new Date();
  tmpObj[currentInstance].home.ts = date.getTime();
  const newData = JSON.stringify(tmpObj);
  localStorage.setItem("store_composeData", newData);
  location.reload();
})();