Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

MediaWiki:Common.js: Difference between revisions

MediaWiki interface page
Content deleted Content added
XPDG (talk | contribs)
No edit summary
Tag: Reverted
XPDG (talk | contribs)
Replaced content with "Any JavaScript here will be loaded for all users on every page load.: //Display Discord widget $( '#discord-widget' ).html( '<iframe class="responsive-iframe" src="https://discord.com/widget?id=647535591818395662&theme=dark" allowtransparency="true" frameborder="0" sandbox="allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts"></iframe>' );"
Tags: Replaced Manual revert
 
Line 3: Line 3:
//Display Discord widget
//Display Discord widget
$( '#discord-widget' ).html( '<iframe class="responsive-iframe" src="https://discord.com/widget?id=647535591818395662&theme=dark" allowtransparency="true" frameborder="0" sandbox="allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts"></iframe>' );
$( '#discord-widget' ).html( '<iframe class="responsive-iframe" src="https://discord.com/widget?id=647535591818395662&theme=dark" allowtransparency="true" frameborder="0" sandbox="allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts"></iframe>' );

//Copy element contents on click - can we replace this?
"use strict";

function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
var copy = document.querySelectorAll(".copy");
var _iterator = _createForOfIteratorHelper(copy),
_step;
try {
var _loop = function _loop() {
var copied = _step.value;
copied.onclick = function () {
document.execCommand("copy");
};
copied.addEventListener("copy", function (event) {
event.preventDefault();
if (event.clipboardData) {
event.clipboardData.setData("text/plain", copied.textContent);
console.log(event.clipboardData.getData("text"));
}
;
});
};
for (_iterator.s(); !(_step = _iterator.n()).done;) {
_loop();
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
;

// Simple calculator
$(document).ready(function () {
// Check if the current page belongs to the desired category
if ($.inArray("Pages with dynamic calculator", mw.config.get("wgCategories")) === -1) {
return; // Exit if the condition is not met
}

// Create the input elements and replace the corresponding span elements
for (var index = 1; index <= 3; index++) {
var spanElement = document.getElementById('simple-calc__rinput' + index);

// Create the input element
var inputElement = document.createElement('input');
inputElement.type = 'text';
inputElement.placeholder = 'Enter a value';
inputElement.id = 'simple-calc__input' + index;

// Replace the span element with the input element
spanElement.parentNode.replaceChild(inputElement, spanElement);
}

// Get the span element to be replaced with the button
var spanElement = document.getElementById('simple-calc__rcalculate');

// Create the button element
var calculateButton = document.createElement('button');
calculateButton.id = 'calculate-btn';
calculateButton.textContent = 'Calculate';

// Add click event listener to the button
calculateButton.addEventListener('click', function () {
// Get the input values
var inputValue1 = parseFloat(document.getElementById('simple-calc__input1').value);
var inputValue2 = parseFloat(document.getElementById('simple-calc__input2').value);
var inputValue3 = parseFloat(document.getElementById('simple-calc__input3').value);

// Perform calculations
var i = inputValue1;
var l = inputValue2;
var j = inputValue3;

// Calculate k based on the seed value
var seedValue = parseFloat(document.getElementById('simple-calc__seed').textContent);

// Output the results
console.log('i = ' + i);
console.log('l = ' + l);
console.log('j = ' + j);
console.log('k = ' + seedValue);

// Calculate the answer based on the simplified equation
var answer = i + (i * (l - seedValue) * 0.01) - ((i + (i * (l - 2) * 0.01)) * (j - 1) * 0.09);

// Round the answer to two decimal places using toFixed
answer = answer.toFixed(2);

// Output the answer
console.log('Your answer is (' + answer + ')');

// Replace the answer element with the calculated answer
var answerElement = document.getElementById('simple-calc__answer');
answerElement.textContent = '₲' + answer;
});

// Replace the span element with the button
spanElement.parentNode.replaceChild(calculateButton, spanElement);
});

Latest revision as of 23:25, 30 May 2025

/* Any JavaScript here will be loaded for all users on every page load. */

//Display Discord widget
$( '#discord-widget' ).html( '<iframe class="responsive-iframe" src="https://discord.com/widget?id=647535591818395662&theme=dark" allowtransparency="true" frameborder="0" sandbox="allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts"></iframe>' );