MediaWiki:Gadget-quickaddnews.js: различия между версиями
Содержимое удалено Содержимое добавлено
Copy-paste from Участник:Zimorodokan/common.js version https://ru.wikinews.org/?oldid=10028779. License from Участник:Zimorodokan/fastAddNewsSourceJS version https://ru.wikinews.org/?oldid=10028676. |
all right here |
||
(не показаны 4 промежуточные версии этого же участника) | |||
Строка 41: | Строка 41: | ||
styleRequest.addEventListener('load', addStyle); |
styleRequest.addEventListener('load', addStyle); |
||
styleRequest.responseType = 'json'; |
styleRequest.responseType = 'json'; |
||
styleRequest.open('GET', 'https://ru.wikinews.org/w/rest.php/v1/page/ |
styleRequest.open('GET', 'https://ru.wikinews.org/w/rest.php/v1/page/MediaWiki:Gadget-quickaddnews.css'); |
||
styleRequest.send(); |
styleRequest.send(); |
||
scriptRequest.addEventListener('load', addScript); |
scriptRequest.addEventListener('load', addScript); |
||
scriptRequest.responseType = 'json'; |
scriptRequest.responseType = 'json'; |
||
scriptRequest.open('GET', 'https://ru.wikinews.org/w/rest.php/v1/page/ |
scriptRequest.open('GET', 'https://ru.wikinews.org/w/rest.php/v1/page/MediaWiki:Gadget-quickaddnews-core.js'); |
||
scriptRequest.send(); |
scriptRequest.send(); |
||
} |
} |
||
if (location.pathname == '/wiki/%D0% |
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(); |
var htmlRequest = new XMLHttpRequest(); |
||
htmlRequest.addEventListener('load', function () { |
htmlRequest.addEventListener('load', function () { |
||
Строка 56: | Строка 56: | ||
}); |
}); |
||
htmlRequest.responseType = 'json'; |
htmlRequest.responseType = 'json'; |
||
htmlRequest.open('GET', 'https://ru.wikinews.org/w/rest.php/v1/page/ |
htmlRequest.open('GET', 'https://ru.wikinews.org/w/rest.php/v1/page/MediaWiki:Gadget-quickaddnews.html'); |
||
htmlRequest.send(); |
htmlRequest.send(); |
||
} |
} |
Текущая версия от 08:13, 7 июня 2021
/*
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();
}
}());