Javascript 是否在单独的网站上将表单字段数据从一个表单复制到另一个表单?
所以我必须在某个网站的表单中输入信息,我们称之为websiteA。我必须在州的另一个网站上输入相同的信息,我们称之为websiteB 我正在寻找一种方法来简化流程,并将来自websiteA的信息自动放置到websiteB上匹配的表单字段中。这只是在我自己的电脑上本地使用 我对这一过程还不熟悉,并且一直在阅读各种不同的方法。我目前正试图在Tampermonkey中这样做,因为这似乎是我做一些研究的最佳选择。Javascript 是否在单独的网站上将表单字段数据从一个表单复制到另一个表单?,javascript,cross-domain,tampermonkey,Javascript,Cross Domain,Tampermonkey,所以我必须在某个网站的表单中输入信息,我们称之为websiteA。我必须在州的另一个网站上输入相同的信息,我们称之为websiteB 我正在寻找一种方法来简化流程,并将来自websiteA的信息自动放置到websiteB上匹配的表单字段中。这只是在我自己的电脑上本地使用 我对这一过程还不熟悉,并且一直在阅读各种不同的方法。我目前正试图在Tampermonkey中这样做,因为这似乎是我做一些研究的最佳选择。 到目前为止,以下是我所拥有的。作为一个例子,我只使用了一个需要名称的表单字段。元素的ID为
到目前为止,以下是我所拥有的。作为一个例子,我只使用了一个需要名称的表单字段。元素的ID为
name
// ==UserScript==
// @name Form Copier
// @namespace http://localhost
// @match https://websiteA.com
// @match https://websiteB.com
// @grant GM_getValue
// @grant GM_setValue
// ==/UserScript==
if(document.URL.indexOf("https://websiteA.com") >= 0){
window.open('https://websiteB.com'); //opens the destination website
document.getElementById("name").value = GM_setValue("name");
}
else if(document.URL.indexOf("https://websiteB.com") >= 0){
document.getElementById("name").value = GM_getValue("name");
}
这是我目前所拥有的,它根本不能正常工作。我一直在努力寻找更好的方法来完成这件事,但运气不好。如果你们能帮助我,我将不胜感激。有几件事:
GM\u setValue()
。看@match
指令的末尾需要一个/*
。(除非你真的想要确切的主页,而不是其他的。)waitforkyellements
(或类似)来处理计时问题// ==UserScript==
// @name Form Copier, Cross-domain
// @match https://Sender.com/*
// @match https://Receiver.com/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_deleteValue
// @grant GM_openInTab
// ==/UserScript==
//-- Wait for the element with the ID "name".
waitForKeyElements ("#name", setOrGetName, true);
function setOrGetName (jNode) {
if (location.hostname == "Sender.com") {
//-- Store the `name` value:
GM_setValue ("nameVal", jNode.val() );
GM_openInTab ("https://Receiver.com/");
}
else if (location.hostname == "Receiver.com") {
var nameVal = GM_getValue ("nameVal");
if (nameVal) {
//-- Set the form value:
jNode.val (nameVal);
//-- Reset storage:
GM_deleteValue ("nameVal");
}
}
}