MediaWiki:Gadget-quickaddnews.js

Материал из Викиновостей, свободного источника новостей

Замечание: Возможно, после публикации вам придётся очистить кэш своего браузера, чтобы увидеть изменения.

  • Firefox / Safari: Удерживая клавишу Shift, нажмите на панели инструментов Обновить либо нажмите Ctrl+F5 или Ctrl+R (⌘+R на Mac)
  • Google Chrome: Нажмите Ctrl+Shift+R (⌘+Shift+R на Mac)
  • Internet Explorer / Edge: Удерживая Ctrl, нажмите Обновить либо нажмите Ctrl+F5
  • Opera: Нажмите Ctrl+F5.
/*
	Copyright 2021 andrij krasotkin

	Licensed under the Apache License, Version 2.0 (the "License");
	you may not use this file except in compliance with the License.
	You may obtain a copy of the License at

	http://www.apache.org/licenses/LICENSE-2.0

	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
*/

'use strict';

(function () {
	function addHTML (htmlString) {
		var parser = new DOMParser();
		var scriptRequest = new XMLHttpRequest();
		var styleRequest = new XMLHttpRequest();
		var doc = parser.parseFromString(htmlString, 'text/html');
		document.replaceChild(doc.documentElement, document.documentElement);

		function addScript () {
			var script = document.createElement('script');
			var scriptContent = scriptRequest.response.source;
			script.insertAdjacentHTML('beforeend', scriptContent);
			document.head.appendChild(script);
		}

		function addStyle () {
			var style = document.createElement('style');
			var styleContent = styleRequest.response.source;
			style.insertAdjacentHTML('beforeend', styleContent);
			document.head.appendChild(style);
		}

		styleRequest.addEventListener('load', addStyle);
		styleRequest.responseType = 'json';
		styleRequest.open('GET', 'https://ru.wikinews.org/w/rest.php/v1/page/MediaWiki:Gadget-quickaddnews.css');
		styleRequest.send();

		scriptRequest.addEventListener('load', addScript);
		scriptRequest.responseType = 'json';
		scriptRequest.open('GET', 'https://ru.wikinews.org/w/rest.php/v1/page/MediaWiki:Gadget-quickaddnews-core.js');
		scriptRequest.send();
	}

	if (location.pathname == '/wiki/%D0%92%D0%B8%D0%BA%D0%B8%D0%BD%D0%BE%D0%B2%D0%BE%D1%81%D1%82%D0%B8:%D0%94%D0%BE%D0%B1%D0%B0%D0%B2%D0%B8%D1%82%D1%8C_%D0%BD%D0%BE%D0%B2%D0%BE%D1%81%D1%82%D1%8C_%D0%B1%D1%8B%D1%81%D1%82%D1%80%D0%BE') {
		var htmlRequest = new XMLHttpRequest();
		htmlRequest.addEventListener('load', function () {
			addHTML(htmlRequest.response.source);
		});
		htmlRequest.responseType = 'json';
		htmlRequest.open('GET', 'https://ru.wikinews.org/w/rest.php/v1/page/MediaWiki:Gadget-quickaddnews.html');
		htmlRequest.send();
	}
}());