mirror of
https://github.com/anticensority/runet-censorship-bypass.git
synced 2024-11-27 20:03:45 +03:00
update button added
This commit is contained in:
parent
97669e886d
commit
9420177df2
|
@ -25,6 +25,6 @@
|
|||
},
|
||||
"options_ui": {
|
||||
"page": "/pages/choose-pac-provider/index.html",
|
||||
"chrome_style": false
|
||||
"chrome_style": true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,21 +7,48 @@
|
|||
list-style-type: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
li {
|
||||
display: block;
|
||||
white-space: nowrap;
|
||||
}
|
||||
li > * {
|
||||
vertical-align: middle;
|
||||
}
|
||||
input[type="radio"], label {
|
||||
cursor: pointer;
|
||||
}
|
||||
.off {
|
||||
display: none;
|
||||
}
|
||||
.link-button, .link-button:visited {
|
||||
color: #0000EE;
|
||||
text-decoration: none;
|
||||
display: none;
|
||||
}
|
||||
.link-button:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
input:checked ~ .link-button {
|
||||
display: inline;
|
||||
}
|
||||
.button-panel {
|
||||
margin-top: 1em;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<ul id="list-of-providers">
|
||||
<li><input type="radio" name="pacProvider" id="none" checked> <label for="none">Отключить</label></li>
|
||||
</ul>
|
||||
<div id='status'>Загрузка...</div>
|
||||
<div style="white-space: nowrap">
|
||||
Обновлялись: <span class="update-date">...</span>
|
||||
</div>
|
||||
<div id="status">Загрузка...</div>
|
||||
<div class="button-panel">
|
||||
<input type="button" value="Готово" class="close-button">
|
||||
</div>
|
||||
<script src="./index.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -11,20 +11,48 @@ chrome.runtime.getBackgroundPage( backgroundPage => {
|
|||
|
||||
var antiCensorRu = backgroundPage.antiCensorRu;
|
||||
|
||||
var ul = document.querySelector('#list-of-providers');
|
||||
var _firstChild = ul.firstChild;
|
||||
for( var providerKey of Object.keys(antiCensorRu.pacProviders) ) {
|
||||
var li = document.createElement('li');
|
||||
li.innerHTML = '<input type="radio" name="pacProvider" id="'+providerKey+'"> <label for="'+providerKey+'">'+providerKey+'</label>';
|
||||
ul.insertBefore( li, _firstChild );
|
||||
// DATE
|
||||
|
||||
var dateForUser = 'неизвестно';
|
||||
if( antiCensorRu.lastPacUpdateStamp ) {
|
||||
var diff = Date.now() - antiCensorRu.lastPacUpdateStamp;
|
||||
var units = ' мс'
|
||||
var gauges = [
|
||||
[1000, ' с'],
|
||||
[60, ' мин'],
|
||||
[60, ' ч'],
|
||||
[24, ' дн'],
|
||||
[7, ' недель'],
|
||||
[4, ' месяцев'],
|
||||
[12, ' г']
|
||||
];
|
||||
for(var g of gauges) {
|
||||
var diffy = Math.floor(diff / g[0]);
|
||||
if (!diffy)
|
||||
break;
|
||||
diff = diffy;
|
||||
var units = g[1];
|
||||
}
|
||||
dateForUser = diff + units + ' назад';
|
||||
}
|
||||
|
||||
var dateElement = document.querySelector('.update-date');
|
||||
dateElement.innerText = dateForUser;
|
||||
dateElement.title = new Date(antiCensorRu.lastPacUpdateStamp).toLocaleString('ru-RU');
|
||||
|
||||
// CLOSE
|
||||
|
||||
document.querySelector('.close-button').onclick = () => window.close();
|
||||
|
||||
// RADIOS
|
||||
|
||||
var currentRadio = () => {
|
||||
var id = antiCensorRu.currentPacProviderKey || 'none';
|
||||
return document.querySelector('#'+id);
|
||||
}
|
||||
var checkChosenProvider = () => {
|
||||
currentRadio().checked = true;
|
||||
var radio = currentRadio();
|
||||
radio.checked = true;
|
||||
}
|
||||
var triggerChosenProvider = () => {
|
||||
var event = document.createEvent('HTMLEvents');
|
||||
|
@ -32,15 +60,25 @@ chrome.runtime.getBackgroundPage( backgroundPage => {
|
|||
currentRadio().dispatchEvent(event);
|
||||
}
|
||||
|
||||
var ul = document.querySelector('#list-of-providers');
|
||||
var _firstChild = ul.firstChild;
|
||||
for( var providerKey of Object.keys(antiCensorRu.pacProviders) ) {
|
||||
var li = document.createElement('li');
|
||||
li.innerHTML = '<input type="radio" name="pacProvider" id="'+providerKey+'"> <label for="'+providerKey+'">'+providerKey+'</label> <a href class="link-button">[обновить]</a>';
|
||||
li.querySelector('.link-button').onclick = () => {triggerChosenProvider(); return false;};
|
||||
ul.insertBefore( li, _firstChild );
|
||||
}
|
||||
|
||||
var radios = [].slice.apply( document.querySelectorAll('[name=pacProvider]') );
|
||||
for(var radio of radios) {
|
||||
radio.onchange = function(event) {
|
||||
var pacKey = event.target.id;
|
||||
if (pacKey === 'none')
|
||||
return antiCensorRu.clearPac( () => window && window.close() );
|
||||
return antiCensorRu.clearPac();
|
||||
|
||||
function enableDisableInputs() {
|
||||
var inputs = document.querySelectorAll('[name="pacProvider"]');
|
||||
var inputs = document.querySelectorAll('input');
|
||||
console.log(inputs.length);
|
||||
for (var i = 0; i < inputs.length; i++)
|
||||
inputs[i].disabled = !inputs[i].disabled;
|
||||
}
|
||||
|
@ -49,7 +87,7 @@ chrome.runtime.getBackgroundPage( backgroundPage => {
|
|||
setStatusTo('Установка...');
|
||||
antiCensorRu.installPac(pacKey, () => {
|
||||
setStatusTo('PAC-скрипт установлен.');
|
||||
if(window) window.close();
|
||||
enableDisableInputs();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,10 +73,14 @@ window.antiCensorRu = {
|
|||
});
|
||||
},
|
||||
|
||||
lastPacUpdateStamp: 0,
|
||||
|
||||
syncWithPacProvider(cb) {
|
||||
setPacScriptFromProvider(
|
||||
this.pacProvider,
|
||||
() => {
|
||||
err => {
|
||||
if (!err)
|
||||
this.lastPacUpdateStamp = Date.now();
|
||||
updatePacProxyIps(
|
||||
this.pacProvider,
|
||||
() => {
|
||||
|
@ -155,7 +159,7 @@ window.antiCensorRu.pullFromStorage( () => {
|
|||
chrome.alarms.onAlarm.addListener(
|
||||
alarm => {
|
||||
if (alarm.name === window.antiCensorRu._periodicUpdateAlarmReason) {
|
||||
console.log('Periodic update triggered.');
|
||||
console.log('Periodic update triggered:', new Date());
|
||||
window.antiCensorRu.syncWithPacProvider();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user