User
Difference between revisions of "Yug/common.js"
< User:Yug
Line 7: | Line 7: | ||
// ==UserScript== | // ==UserScript== | ||
// @name Wikidata Editor | // @name Wikidata Editor | ||
− | + | var entityId = "Q170146"; // Entity to update (Q170146) | |
− | + | var propertyId = "P4"; // Property to update (P4) | |
− | + | var newValue = "Q359"; // Value to set (Q359) | |
− | |||
− | + | // Define the API endpoint | |
− | + | var apiUrl = "https://lingualibre.org/api.php"; | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | // Define the edit summary | |
− | + | var editSummary = "Updating property P4"; | |
− | + | ||
− | + | // Create an object with the data to update | |
− | + | var postData = { | |
− | + | action: "wbsetclaimvalue", | |
− | + | format: "json", | |
− | + | claim: JSON.stringify({ | |
− | + | entity: entityId, | |
− | + | property: propertyId, | |
− | + | snaktype: "value", | |
− | + | value: { | |
− | + | "entity-type": "item", | |
− | + | "numeric-id": newValue.replace("Q", "") | |
− | + | } | |
− | + | }), | |
− | + | summary: editSummary, | |
− | + | token: mw.user.tokens.get("csrfToken") | |
− | + | }; | |
− | + | ||
− | + | // Send a POST request to update the item | |
− | + | $.post(apiUrl, postData, function(data) { | |
− | + | if (data.success) { | |
− | + | console.log("Item updated successfully!"); | |
− | + | } else { | |
− | + | console.error("Error updating item:", data.error.info); | |
− | } | + | } |
+ | }); |
Revision as of 15:23, 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
var entityId = "Q170146"; // Entity to update (Q170146)
var propertyId = "P4"; // Property to update (P4)
var newValue = "Q359"; // Value to set (Q359)
// Define the API endpoint
var apiUrl = "https://lingualibre.org/api.php";
// Define the edit summary
var editSummary = "Updating property P4";
// Create an object with the data to update
var postData = {
action: "wbsetclaimvalue",
format: "json",
claim: JSON.stringify({
entity: entityId,
property: propertyId,
snaktype: "value",
value: {
"entity-type": "item",
"numeric-id": newValue.replace("Q", "")
}
}),
summary: editSummary,
token: mw.user.tokens.get("csrfToken")
};
// Send a POST request to update the item
$.post(apiUrl, postData, function(data) {
if (data.success) {
console.log("Item updated successfully!");
} else {
console.error("Error updating item:", data.error.info);
}
});