mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-22 18:32:45 +01:00
Fix messaging for Safari
This commit is contained in:
parent
6f2e449e61
commit
30ef97a678
@ -210,6 +210,7 @@ var highlightElements = function(elems, force) {
|
||||
var offx = window.pageXOffset;
|
||||
var offy = window.pageYOffset;
|
||||
var islands = [];
|
||||
|
||||
var elem, rect, poly;
|
||||
for ( var i = 0; i < elems.length; i++ ) {
|
||||
elem = elems[i];
|
||||
|
@ -9,19 +9,9 @@ self.vAPI = self.vAPI || {};
|
||||
|
||||
if (/^www\.youtube(-nocookie)?\.com/.test(location.host)) {
|
||||
vAPI.sitePatch = function() {
|
||||
var onWindowLoad = function() {
|
||||
this.removeEventListener('load', onWindowLoad, true);
|
||||
var spf = this._spf_state;
|
||||
|
||||
if (spf && (spf = spf.config)) {
|
||||
spf['navigate-limit'] = 0;
|
||||
spf['navigate-part-received-callback'] = function(url) {
|
||||
window.location.href = url;
|
||||
};
|
||||
}
|
||||
};
|
||||
window.addEventListener('load', onWindowLoad, true);
|
||||
|
||||
// disable spf
|
||||
window.ytspf = {};
|
||||
Object.defineProperty(ytspf, 'enabled', {'value': false});
|
||||
|
||||
// based on ExtendTube's ad removing solution
|
||||
var p, yt = {}, config_ = {}, ytplayer = {}, playerConfig = { args: {} };
|
||||
|
@ -32,66 +32,6 @@
|
||||
|
||||
var exports = {};
|
||||
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
/*exports.gotoExtensionURL = function(url) {
|
||||
|
||||
var hasQuery = function(url) {
|
||||
return url.indexOf('?') >= 0;
|
||||
};
|
||||
|
||||
var removeQuery = function(url) {
|
||||
var pos = url.indexOf('?');
|
||||
if ( pos < 0 ) {
|
||||
return url;
|
||||
}
|
||||
return url.slice(0, pos);
|
||||
};
|
||||
var removeFragment = function(url) {
|
||||
var pos = url.indexOf('#');
|
||||
if ( pos < 0 ) {
|
||||
return url;
|
||||
}
|
||||
return url.slice(0, pos);
|
||||
};
|
||||
|
||||
var tabIndex = 9999;
|
||||
var targetUrl = vAPI.getURL(url);
|
||||
|
||||
var currentWindow = function(tabs) {
|
||||
var updateProperties = { active: true };
|
||||
var i = tabs.length;
|
||||
while ( i-- ) {
|
||||
if ( removeQuery(tabs[i].url) !== removeQuery(targetUrl) ) {
|
||||
continue;
|
||||
}
|
||||
// If current tab in dashboard is different, force the new one, if
|
||||
// there is one, to be activated.
|
||||
if ( tabs[i].url !== targetUrl ) {
|
||||
updateProperties.url = targetUrl;
|
||||
}
|
||||
chrome.tabs.update(tabs[i].id, updateProperties);
|
||||
return;
|
||||
}
|
||||
chrome.tabs.create({ 'url': targetUrl, index: tabIndex + 1 });
|
||||
};
|
||||
|
||||
var currentTab = function(tabs) {
|
||||
if ( tabs.length ) {
|
||||
tabIndex = tabs[0].index;
|
||||
}
|
||||
chrome.tabs.query({ currentWindow: true }, currentWindow);
|
||||
};
|
||||
|
||||
// https://github.com/gorhill/httpswitchboard/issues/150
|
||||
// Logic:
|
||||
// - If URL is already opened in a tab, just activate tab
|
||||
// - Otherwise find the current active tab and open in a tab immediately
|
||||
// to the right of the active tab
|
||||
chrome.tabs.query({ active: true }, currentTab);
|
||||
};*/
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
exports.formatCount = function(count) {
|
||||
|
@ -531,7 +531,7 @@ if (self.chrome) {
|
||||
details.code = xhr.responseText;
|
||||
}
|
||||
|
||||
tab.page.dispatchMessage('message', {
|
||||
tab.page.dispatchMessage('broadcast', {
|
||||
portName: 'vAPI',
|
||||
msg: {
|
||||
cmd: 'runScript',
|
||||
@ -713,7 +713,7 @@ if (self.chrome) {
|
||||
};
|
||||
|
||||
for (var tabId in vAPI.tabs.stack) {
|
||||
vAPI.tabs.stack[tabId].page.dispatchMessage('message', message);
|
||||
vAPI.tabs.stack[tabId].page.dispatchMessage('broadcast', message);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -121,7 +121,8 @@ if (self.chrome) {
|
||||
// messages from the background script are sent to every frame,
|
||||
// so we need to check the connectorId to accept only
|
||||
// what is meant for the current context
|
||||
if (msg.name === vAPI.messaging.connectorId) {
|
||||
if (msg.name === vAPI.messaging.connectorId
|
||||
|| msg.name === 'broadcast') {
|
||||
vAPI.messaging.connector(msg.message);
|
||||
}
|
||||
};
|
||||
|
@ -27,8 +27,8 @@ def mkdirs(path):
|
||||
return osp.exists(path)
|
||||
|
||||
|
||||
meta_dir = pj('meta')
|
||||
src_dir = pj('src')
|
||||
meta_dir = pj('meta')
|
||||
|
||||
with open(pj(meta_dir, 'config.json'), encoding='utf-8') as f:
|
||||
config = json.load(f)
|
||||
@ -36,15 +36,10 @@ with open(pj(meta_dir, 'config.json'), encoding='utf-8') as f:
|
||||
vendors = config['vendors']
|
||||
del config['vendors']
|
||||
|
||||
src_dir = pj('src')
|
||||
source_locale_dir = pj('src', '_locales')
|
||||
target_locale_dir = pj('src', 'locale')
|
||||
descriptions = OrderedDict({})
|
||||
|
||||
tmp = datetime.now() - datetime(year=datetime.today().year, month=1, day=1)
|
||||
config['build_number'] = strftime('%y' + str(int(tmp.total_seconds() * 65535 / 31536000)).zfill(5))
|
||||
|
||||
rmtree(target_locale_dir)
|
||||
descriptions = OrderedDict({})
|
||||
|
||||
|
||||
with open(pj(src_dir, 'js', 'vapi-appinfo.js'), 'r+t', encoding='utf-8', newline='\n') as f:
|
||||
@ -58,25 +53,13 @@ with open(pj(src_dir, 'js', 'vapi-appinfo.js'), 'r+t', encoding='utf-8', newline
|
||||
))
|
||||
|
||||
|
||||
for alpha2 in os.listdir(source_locale_dir):
|
||||
with open(pj(source_locale_dir, alpha2, 'messages.json'), encoding='utf-8') as f:
|
||||
string_data = json.load(f, object_pairs_hook=OrderedDict)
|
||||
with open(pj(src_dir, vendors['crx']['manifest']), 'wt', encoding='utf-8', newline='\n') as f:
|
||||
with open(pj(meta_dir, 'crx', vendors['crx']['manifest']), 'r') as cf:
|
||||
cf_content = cf.read()
|
||||
|
||||
alpha2 = alpha2.replace('_', '-')
|
||||
|
||||
mkdirs(pj(target_locale_dir, alpha2))
|
||||
|
||||
with open(pj(target_locale_dir, alpha2, 'messages.properties'), 'wt', encoding='utf-8', newline='\n') as f:
|
||||
descriptions[alpha2] = {}
|
||||
|
||||
for string_name in string_data:
|
||||
if string_name == 'extShortDesc':
|
||||
descriptions[alpha2] = string_data[string_name]['message']
|
||||
|
||||
f.write(string_name)
|
||||
f.write('=')
|
||||
f.write(string_data[string_name]['message'].replace('\n', r'\n'))
|
||||
f.write('\n')
|
||||
f.write(
|
||||
re.sub(r"\{(?=\W)|(?<=\W)\}", r'\g<0>\g<0>', cf_content).format(**config)
|
||||
)
|
||||
|
||||
|
||||
with open(pj(src_dir, 'locales.json'), 'wt', encoding='utf-8', newline='\n') as f:
|
||||
@ -90,15 +73,6 @@ with open(pj(src_dir, 'locales.json'), 'wt', encoding='utf-8', newline='\n') as
|
||||
json.dump(tmp, f, sort_keys=True, ensure_ascii=False)
|
||||
|
||||
|
||||
with open(pj(src_dir, vendors['crx']['manifest']), 'wt', encoding='utf-8', newline='\n') as f:
|
||||
with open(pj(meta_dir, 'crx', vendors['crx']['manifest']), 'r') as cf:
|
||||
cf_content = cf.read()
|
||||
|
||||
f.write(
|
||||
re.sub(r"\{(?=\W)|(?<=\W)\}", r'\g<0>\g<0>', cf_content).format(**config)
|
||||
)
|
||||
|
||||
|
||||
with open(pj(src_dir, vendors['safariextz']['manifest']['Info']), 'wt', encoding='utf-8', newline='\n') as f:
|
||||
config['app_id'] = vendors['safariextz']['app_id']
|
||||
config['description'] = descriptions[config['def_lang']]
|
||||
|
Loading…
Reference in New Issue
Block a user