User

Difference between revisions of "Yug/common.js"

< User:Yug

Line 4: Line 4:
 
  mw.loader.load( '/index.ptitle=User:Elfix/MediaWiki:SoundLibrary.js&action=raw&ctype=text/javascript');  
 
  mw.loader.load( '/index.ptitle=User:Elfix/MediaWiki:SoundLibrary.js&action=raw&ctype=text/javascript');  
 
}
 
}
 
 
// ==UserScript==
 
// @name        Wikidata Editor
 
// @namespace    https://example.com
 
// @version      1.0
 
// @description  Edit a Wikidata page
 
// @include      https://www.wikidata.org/wiki/Q*
 
// @grant        GM_xmlhttpRequest
 
// ==/UserScript==
 
 
// ==UserScript==
 
// @name        Wikidata Editor
 
// @namespace    https://example.com
 
// @version      1.0
 
// @description  Edit a Wikidata page
 
// @include      https://www.wikidata.org/wiki/Q*
 
// @grant        none
 
// ==/UserScript==
 
  
 
// ==UserScript==
 
// ==UserScript==
Line 46: Line 27:
  
 
     // Fetch current data
 
     // Fetch current data
     fetch("https://lingualibre.org/api?action=wbgetentities&format=json&ids=" + entityId)
+
     fetch("https://lingualibre.org/api?action=wbgetentities&format=json&id=" + entityId)  
        .then(function(response) {
+
    .then(function(response) {
 
             return response.json();
 
             return response.json();
 
         })
 
         })

Revision as of 14:39, 2 October 2023

// Modules loader, conditional
// Sound library
if(/^User:Elfix\/LinguaLibre:Explore_the_sound_library(\/[a-z_-]+)?$/.test( mw.config.get( 'wgPageName' ) ) ) {
 mw.loader.load( '/index.ptitle=User:Elfix/MediaWiki:SoundLibrary.js&action=raw&ctype=text/javascript'); 
}

// ==UserScript==
// @name         Wikidata Editor
// @namespace    https://example.com
// @version      1.0
// @description  Edit a Wikidata page
// @include      https://www.wikidata.org/wiki/Q*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Your Wikidata entity ID (QID)
    var entityId = "Q170146";

    // Property ID (P4)
    var propertyId = "P4";

    // Value to set (Q359)
    var newValue = "Q359";

    // Fetch current data
    fetch("https://lingualibre.org/api?action=wbgetentities&format=json&id=" + entityId) 
    .then(function(response) {
            return response.json();
        })
        .then(function(data) {
            if (data.success) {
                // Modify data
                data.entities[entityId].claims[propertyId] = [
                    {
                        mainsnak: {
                            snaktype: "value",
                            property: propertyId,
                            datavalue: {
                                value: {
                                    "entity-type": "item",
                                    "numeric-id": newValue.replace("Q", "")
                                },
                                type: "wikibase-entityid"
                            }
                        },
                        rank: "normal",
                        references: [],
                    }
                ];

                // Submit changes
                fetch("https://lingualibre.org/api?action=wbeditentity&format=json", {
                    method: "POST",
                    body: JSON.stringify({
                        id: entityId,
                        data: JSON.stringify(data.entities[entityId]),
                        summary: "Updating property P4",
                    }),
                    headers: {
                        "Content-Type": "application/x-www-form-urlencoded",
                    },
                })
                .then(function(response) {
                    return response.json();
                })
                .then(function(responseData) {
                    console.log("Edit response:", responseData);
                })
                .catch(function(error) {
                    console.error("An error occurred:", error);
                });
            }
        })
        .catch(function(error) {
            console.error("An error occurred:", error);
        });
})();