User:Coderreyansh/vector-2022.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | The accompanying .css page for this skin is at User:Coderreyansh/vector-2022.css. |
//<nowiki>
// 1. Add a Custom Tab for Wikification
mw.loader.using('mediawiki.util', function () {
$(document).ready(function () {
var link = mw.util.addPortletLink('p-cactions', '#', 'Wikify', 'ca-wikify', 'Mark for wikification');
$(link).click(function (event) {
event.preventDefault();
doWikify();
});
});
});
function doWikify() {
// Code to mark the article for wikification
var text = "{{Wikify}}";
var textarea = document.getElementById("wpTextbox1");
textarea.value += text;
}
// 2. Automate Adding Categories
mw.hook('wikipage.content').add(function ($content) {
if ($content.is('#mw-content-text')) {
var category = "[[Category:New Pages]]";
var textarea = document.getElementById("wpTextbox1");
textarea.value += category;
}
});
// 3. Enhance Search Functionality
$(document).ready(function () {
var searchBox = $('<input id="customSearch" type="text" placeholder="Search Wikipedia">');
searchBox.appendTo('#p-search');
searchBox.autocomplete({
source: function (request, response) {
$.ajax({
url: mw.util.wikiScript('api'),
dataType: "json",
data: {
action: 'opensearch',
search: request.term,
limit: 10,
format: 'json'
},
success: function (data) {
response(data);
}
});
},
select: function (event, ui) {
window.location.href = ui.item.value;
}
});
});
// 4. Color Code User Contributions
$(document).ready(function () {
var contributions = $('#mw-content-text ul');
contributions.find('li').each(function () {
var link = $(this).find('a');
if (link.text().includes('edit')) {
$(this).css('background-color', '#cff');
} else if (link.text().includes('new')) {
$(this).css('background-color', '#ffc');
} else if (link.text().includes('move')) {
$(this).css('background-color', '#fcc');
}
});
});
// 5. Add Quick Links to Toolbox
$(document).ready(function () {
var toolbox = $('#p-tb');
var link = $('<a href="#">Quick Link</a>').attr('title', 'Quick Link');
link.appendTo(toolbox);
link.click(function (event) {
event.preventDefault();
// Custom action for the link
alert('Quick Link clicked!');
});
});
// 6. Highlight Unsaved Changes
$(document).ready(function () {
var originalText = document.getElementById("wpTextbox1").value;
document.getElementById("wpTextbox1").oninput = function () {
if (this.value !== originalText) {
this.style.background = 'rgba(255, 255, 0, 0.2)';
} else {
this.style.background = '';
}
};
});
// 7. Automate Edit Summaries
$(document).ready(function () {
var summary = document.getElementById("wpSummary");
if (summary.value === '') {
summary.value = 'Default edit summary';
}
});
// 8. Display Page Metrics
$(document).ready(function () {
$.getJSON(mw.util.wikiScript('api'), {
action: 'query',
titles: mw.config.get('wgPageName'),
prop: 'revisions|pageviews',
rvprop: 'ids',
pvipdays: 30,
format: 'json'
}, function (data) {
var pageId = Object.keys(data.query.pages);
var edits = data.query.pages[pageId].revisions.length;
var views = data.query.pages[pageId].pageviews;
var metrics = $('<div>Edits: ' + edits + ', Views: ' + views + '</div>');
metrics.appendTo('#bodyContent');
});
});
// 9. Customize Watchlist
$(document).ready(function () {
var watchlist = $('#watchlist');
var button = $('<button>Remove from Watchlist</button>');
button.appendTo(watchlist);
button.click(function (event) {
event.preventDefault();
var pageName = mw.config.get('wgPageName');
$.getJSON(mw.util.wikiScript('api'), {
action: 'watch',
title: pageName,
unwatch: true,
format: 'json'
}, function (data) {
if (data.watch.unwatch) {
alert('Page removed from watchlist');
}
});
});
});
// 10. Enhance Navigation
$(document).ready(function () {
var navMenu = $('<ul id="customNav"></ul>');
navMenu.appendTo('#p-navigation');
var pages = ['Main_Page', 'Special:RecentChanges', 'Special:Watchlist'];
pages.forEach(function (page) {
var link = $('<a href="' + mw.util.wikiScript(page) + '">' + page.replace(/_/g, ' ') + '</a>');
link.wrap('<li>').parent().appendTo(navMenu);
});
});
//</nowiki>