Chrome 自动运行JavaScript脚本片段

oaxa6hgo  于 2023-08-01  发布在  Go
关注(0)|答案(1)|浏览(99)

我想在SAP BO“查询生成器”上运行一个脚本片段,它是一个使用SQL检索数据的简单工具。(由于信誉问题,我无法上传图片,产品的界面可以在这里找到:http://scn.sap.com/docs/DOC-42952
由于我有一堆查询要运行,我想使用snippet来自动运行它们。使用以下代码:

//select the textarea to insert retrieved queries
    document.querySelector("textarea").textContent = "SELECT * FROM CI_INFOOBJECTS";
    //click the submit button
    document.getElementsByTagName('input')[0].click();

    //code to export the query result

    //after click(), the page reloaded and it won't executed the following code.
    document.addEventListener("DOMContentLoaded", function() {
    //back to the previous page, run the previous code again
        window.history.back(1);
        }, false);

字符串
有没有人有好的想法如何实现它?谢谢你的帮助。

ca1c2owp

ca1c2owp1#

你可以在chrome上使用Tampermonkey,你可以从hibbard tampermonkey tutorial这样的网站上学习如何使用它。总的来说,你的脚本看起来像这样:

// ==UserScript==
// @name         Enter any name you like here
// @namespace    URL of website you own 
// @version      0.1
// @description  retrive data using sql
// @author       Your name here
// @match        relevant url
// ==/UserScript==
/* jshint -W097 */


// Your code here...
//select the textarea to insert retrieved queries
    document.querySelector("textarea").textContent = "SELECT * FROM CI_INFOOBJECTS";
    //click the submit button
    document.getElementsByTagName('input')[0].click();

    //code to export the query result

    //after click(), the page reloaded and it won't executed the following code.
    document.addEventListener("DOMContentLoaded", function() {
    //back to the previous page, run the previous code again
        window.history.back(1);
        }, false);

进行必要的更改,如@match。请评论如果你有任何疑问。希望有帮助

相关问题