Sparql to QuickStatements

Copy commands from Sparql to QuickStatements

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Sparql to QuickStatements
// @namespace    https://greasyfork.org/users/21515
// @version      0.1.1
// @description  Copy commands from Sparql to QuickStatements
// @author       CennoxX
// @homepage     https://github.com/CennoxX/userscripts
// @supportURL   https://github.com/CennoxX/userscripts/issues/new?title=[Sparql%20to%20QuickStatements]%20
// @match        https://query.wikidata.org/
// @match        https://quickstatements.toolforge.org/
// @icon         https://www.google.com/s2/favicons?sz=64&domain=wikidata.org
// @grant        GM_setValue
// @grant        GM_getValue
// @license      MIT
// ==/UserScript==
/* jshint esversion: 10 */
/* eslint quotes: ["warn", "double", {"avoidEscape": true}] */
/* eslint curly: "off" */

(function() {
    "use strict";
    if (location.host == "query.wikidata.org") {
        GM_setValue("qsLastTimeOpened",0);
        var oldResponse = "";
        var mainLoop = setInterval(function(){
            var response = document.getElementById("response-summary").innerText;
            if (response && oldResponse != response){
                oldResponse = response;
                console.clear();
                if (!document.getElementById("qs-run")){
                    addQSButton();
                }
            }
        }, 500);

        function addQSButton(){
            var navbar = document.getElementsByClassName("navbar navbar-default result")[0].getElementsByClassName("nav navbar-nav navbar-right")[0];
            var liNode = document.createElement("li");
            liNode.innerHTML = '<a id="qs-run" class="btn" data-toggle="modal" title="Copy to QuickStatements"><span class="fa fa-rocket"></span><span> QuickStatements</span></a>';
            navbar.appendChild(liNode);
            liNode.addEventListener("click", function() {startQuickStatements();});
        }

        function startQuickStatements(){
            var commands = document.querySelector(".fixed-table-body tbody").innerText;
            GM_setValue("quickstatements",commands);
            document.querySelector("#qs-run>span").style.color="#14866d";
            var qsLastTimeOpened = GM_getValue("qsLastTimeOpened");
            var oneSecondbefore = new Date().getTime() - 1000;
            if (oneSecondbefore > qsLastTimeOpened){
                window.open("https://quickstatements.toolforge.org/#/batch", "_blank").focus();
            }
        }

    } else if (location.host == "quickstatements.toolforge.org"){
        var quickstatements = "";
        var evt = document.createEvent("HTMLEvents");
        evt.initEvent("input", false, true);
        var checkForChanges = setInterval(function() {
            var quickForm = document.querySelector("textarea.form-control");
            if (quickForm){
                GM_setValue("qsLastTimeOpened", new Date().getTime());
            }
            if (quickstatements) {
                if (!quickForm.innerHTML.includes(quickstatements)){
                    quickForm.innerHTML += quickstatements + "\n";
                    quickForm.innerHTML = quickForm.innerHTML.replace("||\n","||");
                    quickForm.dispatchEvent(evt);
                }
                GM_setValue("quickstatements","");
                quickstatements = "";
            }else{
                quickstatements = GM_getValue("quickstatements");
            }
        }, 250);
    }
})();