பயனர்:Maathavan/QuoteHighlighter.js
குறிப்பு - சேமித்த பின்னர், நீங்கள் செய்த மாற்றங்களைக் காண்பதற்கு உங்கள் உலவியின் இடைமாற்று அகற்றப்பட வேண்டும்.
- மொஸில்லா பயர்பாக்ஸ் / சபாரி: Shift+Reload, அல்லது Ctrl-F5 அல்லது Ctrl-R (⌘-R Mac ல்)
- கூகிள் குரோம் Ctrl-Shift-R அழுத்தவும். (⌘-Shift-R Mac ல்) ;
- இண்டர்நெட் எக்ஸ்ப்ளோரர்: Ctrl-Refresh அல்லது Ctrl-F5 ஐ அழுத்தவும்.
- ஒபேரா: Tools → Preferences இல் இடைமாற்றை அகற்றவும்;
var highlight = localStorage.getItem('quoteHighlight') ? localStorage.getItem('quoteHighlight') : false;
if (mw.config.get("wgNamespaceNumber") !== 2) {
$(".mw-indicators").prepend('<div class="mw-indicator"><a class="CETLinkDisable" id="quotesHighlight" href="#" title="Highlight Quotes!"><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/3/30/OOjs_UI_icon_highlight-progressive.svg/20px-OOjs_UI_icon_highlight-progressive.svg.png" decoding="async" width="21" height="21"></a></div>');
$("#quotesHighlight").click(function () {
localStorage.setItem('quoteHighlight', highlight == 'false');
location.reload();
});
highlightQuote();
}
function highlightQuote() {
if (highlight == "true") {
$.ajax({
url: mw.config.get("wgScriptPath") + '/api.php?',
data: 'action=query&format=json&prop=revisions&indexpageids=1&titles=' + encodeURIComponent(mw.config.get("wgPageName")) + '&utf8=1&rvprop=content',
dataType: 'json',
success: function (data) {
var pageid = data.query.pageids[0];
var t = '*';
var wikiPageContent = data.query.pages[pageid].revisions[0][t];
var singleQuotes = wikiPageContent.match(/'(.*?)'|'(.*?)(?:(?:\r\n|[\r\n])[^\r\n]+)*'/g) || [];
var doubleQuotes = wikiPageContent.match(/"(.*?)"|"(.*?)(?:(?:\r\n|[\r\n])[^\r\n]+)*"/g) || [];
var highlightTexts = singleQuotes.concat(doubleQuotes);
console.log(highlightTexts);
var content = $('.mw-parser-output').html();
for (var i = 0; i < highlightTexts.length; i++) {
if (highlightTexts[i].indexOf('"') === 0) {
content = content.replace(highlightTexts[i], '<font style="background:lightgreen;" >' + highlightTexts[i] + '</font>');
} else {
content = content.replace(highlightTexts[i], '<font style="background:lightblue;" >' + highlightTexts[i] + '</font>');
}
}
$('.mw-parser-output').html(content);
}
});
}
}