bypass-paywalls-firefox-clean/options/version.js

105 lines
4.2 KiB
JavaScript
Raw Normal View History

2022-02-20 08:25:25 +01:00
var ext_api = (typeof browser === 'object') ? browser : chrome;
var manifestData = ext_api.runtime.getManifest();
2024-01-10 08:54:04 +01:00
var url_loc = manifestData.key ? 'chrome' : 'firefox';
var version_str = 'v' + manifestData.version;
var version_span = document.querySelector('span#version');
if (version_span)
version_span.innerText = version_str;
var version_span_new = document.querySelector('span#version_new');
if (version_span_new)
version_span_new.setAttribute('style', 'font-weight: bold;');
2020-12-01 17:53:32 +01:00
var anchorEl;
function show_update(ext_version_new, ext_upd_version_new = '', check = true) {
2022-01-30 18:23:28 +01:00
if (ext_version_new) {
ext_api.management.getSelf(function (result) {
var installType = result.installType;
var version_len = (installType === 'development') ? 7 : 5;
if (version_len === 5 && ext_upd_version_new && ext_upd_version_new < ext_version_new)
ext_version_new = ext_upd_version_new;
2022-01-30 18:23:28 +01:00
if (ext_version_new.substring(0, version_len) > manifestData.version.substring(0, version_len)) {
ext_api.storage.local.set({
ext_version_new: ext_version_new
});
2022-01-30 18:23:28 +01:00
anchorEl = document.createElement('a');
anchorEl.target = '_blank';
2024-01-10 08:54:04 +01:00
let manifest_id = manifestData.browser_specific_settings ? manifestData.browser_specific_settings.gecko.id : '';
if (manifest_id && manifest_id.includes('magnolia')) {
2022-01-30 18:23:28 +01:00
if (installType === 'development')
2022-02-20 08:25:25 +01:00
anchorEl.href = 'https://gitlab.com/magnolia1234/bypass-paywalls-' + url_loc + '-clean';
2022-11-10 08:44:10 +01:00
else {
2022-02-20 08:25:25 +01:00
anchorEl.href = 'https://gitlab.com/magnolia1234/bypass-paywalls-' + url_loc + '-clean/-/releases';
2022-11-10 08:44:10 +01:00
ext_version_new = ext_version_new.replace(/\d$/, '0');
}
2023-02-11 09:20:49 +01:00
}
2022-11-10 08:44:10 +01:00
if (installType !== 'development')
ext_version_new = ext_version_new.replace(/\d$/, '0');
anchorEl.innerText = 'New release v' + ext_version_new;
2022-01-30 18:23:28 +01:00
anchorEl.target = '_blank';
2024-01-10 08:54:04 +01:00
version_span_new.appendChild(anchorEl);
let warning;
2022-01-30 18:23:28 +01:00
if (!manifestData.name.includes('Clean')) {
warning = 'fake';
} else if (manifest_id && !manifest_id.match(/^magnolia(_limited_permissions)?@12\.34$/)) {
warning = 'cloned';
}
if (warning) {
2022-01-30 18:23:28 +01:00
let par = document.createElement('p');
2023-12-24 09:06:19 +01:00
par.innerText = "You've installed a " + warning + " version of BPC (check help/GitLab)";
par.style = 'font-weight: bold;';
2024-01-10 08:54:04 +01:00
version_span_new.appendChild(par);
2022-01-30 18:23:28 +01:00
}
}
});
} else if (check) {
anchorEl = document.createElement('a');
anchorEl.text = 'Check Twitter for latest update';
anchorEl.href = 'https://twitter.com/Magnolia1234B';
anchorEl.target = '_blank';
2024-01-10 08:54:04 +01:00
version_span_new.appendChild(anchorEl);
2022-01-30 18:23:28 +01:00
}
}
function check_version_update(ext_version_new, popup) {
if (!popup) {
2022-02-20 08:25:25 +01:00
let manifest_new = 'https://gitlab.com/magnolia1234/bypass-paywalls-' + url_loc + '-clean/raw/master/manifest.json';
fetch(manifest_new)
2022-01-30 18:23:28 +01:00
.then(response => {
if (response.ok) {
response.json().then(json => {
var version_new = json['version'];
if (manifestData.browser_specific_settings && manifestData.browser_specific_settings.gecko.update_url) {
let json_upd_version_new = manifestData.browser_specific_settings.gecko.update_url;
fetch(json_upd_version_new)
.then(response => {
if (response.ok) {
response.json().then(upd_json => {
let ext_id = manifestData.browser_specific_settings.gecko.id;
let upd_version_new = upd_json.addons[ext_id].updates[0].version;
show_update(version_new, upd_version_new);
})
}
}).catch(function (err) {
false;
});
} else
show_update(version_new);
2022-01-30 18:23:28 +01:00
})
} else {
show_update(ext_version_new);
}
}).catch(function (err) {
false;
});
} else
show_update(ext_version_new, '', false);
}
2022-01-30 18:23:28 +01:00
ext_api.storage.local.get({optInUpdate: true, ext_version_new: false}, function (result) {
if (result.optInUpdate) {
let popup = document.querySelector('script[id="popup"]');
check_version_update(result.ext_version_new, popup);
}
});