Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: background.js

Issue 8483154: Adding ABP core modules to ABP/Opera (Closed)
Patch Set: Created Oct. 9, 2012, 9:51 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | button.js » ('j') | button.js » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /*opera.extension.windows.addEventListener( "focus", function(){ 1 var FilterNotifier = require("filterNotifier").FilterNotifier;
2 » opera.postError('Focus: ' + opera.extension.tabs.getSelected().url); 2 var FilterStorage = require("filterStorage").FilterStorage;
3 var Synchronizer = require("synchronizer").Synchronizer;
4 var Subscription = require("subscriptionClasses").Subscription;
5 var DownloadableSubscription = require("subscriptionClasses").DownloadableSubscr iption;
6
7 var isFirstRun = false;
8 FilterNotifier.addListener(function(action)
9 {
10 if (action == "load")
11 {
12 importOldData();
13 if (!window.localStorage.currentVersion)
14 {
15 isFirstRun = true;
16 executeFirstRunActions();
17 }
18 window.localStorage.currentVersion = require("info").addonVersion;
19 }
3 }); 20 });
4 opera.extension.windows.addEventListener( "change", function(){
5 opera.postError('Change: ' + opera.extension.tabs.getSelected());
6 });
7 opera.extension.windows.addEventListener( "create", function(){
8 opera.postError('Create: ' + opera.extension.tabs.getSelected());
9 });
10 opera.extension.windows.addEventListener( "update", function(){
11 opera.postError('Update: ' + opera.extension.tabs.getSelected());
12 });*/
13 21
14 opera.extension.onmessage = function (event) { 22 function importOldData()
15 » button.update(); 23 {
16 » //opera.postError('BACKGROUND: got a ' + event.data.request + ' request' ); 24 // TODO: Remove this once most people have the update
17 » switch(event.data.request) { 25 if ("version" in widget.preferences)
18 » » case 'css': 26 {
19 » » » //opera.postError('BACKGROUND: got reply from ' + event. data.url); 27 var oldLists = {
20 » » » if(whitelist.check(event.data.url)) 28 "fanboy": "https://secure.fanboy.co.nz/fanboy-adblock.txt",
21 » » » » event.source.postMessage({request: event.data.re quest, reply: css.personal().join("\n"), id: 'OAB_Perso'}); 29 "fanboy-ru": "https://secure.fanboy.co.nz/fanboy-russian.txt",
22 » » » else 30 "fanboy-es": "https://secure.fanboy.co.nz/fanboy-espanol.txt",
23 » » » » event.source.postMessage({request: event.data.re quest, reply: '', id: 'OAB_Perso'}); 31 "fanboy-ja": "https://secure.fanboy.co.nz/fanboy-japanese.txt",
24 » » » 32 "fanboy-cz": "https://secure.fanboy.co.nz/fanboy-czech.txt",
25 » » » for(key in sources.css) { //Sends them one by one to avo id contamination in cases where one is corrupted 33 "fanboy-tr": "https://secure.fanboy.co.nz/fanboy-turkish.txt",
26 » » » » if(css.status(key) && whitelist.check(event.data .url)) 34 "fanboy-pl": "https://secure.fanboy.co.nz/fanboy-polish.txt",
27 » » » » » event.source.postMessage({request: event .data.request, reply: css.get(key).join("\n"), id: 'OAB_' + key}); 35 "fanboy-vi": "https://secure.fanboy.co.nz/fanboy-vietnam.txt",
28 » » » » else 36 "fanboy-sv": "https://secure.fanboy.co.nz/fanboy-swedish.txt",
29 » » » » » event.source.postMessage({request: event .data.request, reply: '', id: 'OAB_' + key}); 37 "fanboy-ko": "https://secure.fanboy.co.nz/fanboy-korean.txt",
30 » » » } 38 "fanboy-ann": "https://secure.fanboy.co.nz/fanboy-addon.txt",
31 » » » break; 39 "easy": "https://easylist-downloads.adblockplus.org/easylist.txt",
32 » » case 'ping': 40 "easy-ru": "https://ruadlist.googlecode.com/svn/trunk/advblock.txt",
33 » » » //opera.postError('BACKGROUND: ping received'); 41 "easy-de": "https://easylist-downloads.adblockplus.org/easylistgermany.txt ",
34 » » » opera.extension.broadcastMessage({request: 'ping', type: event.data.type}); 42 "easy-fr": "http://lian.info.tm/liste_fr.txt",
35 » » » break; 43 "easy-zh": "https://adblock-chinalist.googlecode.com/svn/trunk/adblock.txt ",
36 » » case 'list': 44 "easy-id": "https://indonesianadblockrules.googlecode.com/hg/subscriptions /abpindo.txt",
37 » » » if(event.data.enable) 45 "easy-bg": "http://stanev.org/abp/adblock_bg.txt",
38 » » » » lists.enable(event.data.key); 46 "easy-ja": "https://adblock-plus-japanese-filter.googlecode.com/hg/abp_jp. txt",
39 » » » else 47 "easy-el": "https://www.void.gr/kargig/void-gr-filters.txt",
40 » » » » lists.disable(event.data.key); 48 "easy-pl": "http://adblocklist.org/adblock-pxf-polish.txt",
41 » » » break; 49 "easy-nl": "https://dutchadblockfilters.googlecode.com/svn/trunk/AdBlock_D utch_hide.txt",
42 » » case 'whitelist': //request: whitelist // type: add | remove // rule: RULE 50 "easy-ro": "http://www.zoso.ro/pages/rolist.txt",
43 » » » if(event.data.type == 'add') 51 "easy-fi": "http://www.wiltteri.net/wiltteri.txt",
44 » » » » opera.extension.urlfilter.allow.add(event.data.r ule); 52 "easy-es": "http://abp.mozilla-hispano.org/nauscopio/filtros.txt",
45 » » » else if(event.data.type == 'remove') 53 "easy-hu": "http://ajnasz.hu/adblock/recent",
46 » » » » opera.extension.urlfilter.allow.remove(event.dat a.rule); 54 "adblock-lv": "https://gitorious.org/adblock-latvian/adblock-latvian/blobs /raw/master/lists/latvian-list.txt",
47 » » » break; 55 "easy-priv": "https://easylist-downloads.adblockplus.org/easyprivacy.txt",
48 » » /*case 'button': 56 "easy-ru-priv": "https://ruadlist.googlecode.com/svn/trunk/cntblock.txt"
49 » » » if(event.data.enable) 57 };
50 » » » » button.enable(); 58
51 » » » else 59 for (var key in oldLists)
52 » » » » button.disable();*/ 60 {
53 » } 61 if (key in widget.preferences)
62 {
63 // Only add subscriptions that were enabled in old version
64 if (widget.preferences[key] == "true")
65 {
66 var subscription = Subscription.fromURL(oldLists[key]);
67 if (subscription && !(subscription.url in FilterStorage.knownSubscript ions))
68 {
69 FilterStorage.addSubscription(subscription);
70 Synchronizer.execute(subscription);
71 }
72 }
73
74 delete widget.preferences[key];
75 delete widget.preferences[key + "-content"];
76 delete widget.preferences[key + "-time"];
77 }
78 }
79
80 // TODO: Import custom filters?
Felix Dahlke 2012/10/10 12:11:22 Yes, I think we should do that, but it might get h
81
82 delete widget.preferences.version;
83 }
54 } 84 }
55 85
56 if(window.widget.version != preferences.string('version')) { 86 function executeFirstRunActions()
57 » if(!preferences.exist('version')) { // New install 87 {
58 » » lists.enable('easy'); 88 // Don't do anything if the user has a subscription already
59 » } 89 var hasSubscriptions = FilterStorage.subscriptions.some(function(subscription) {return subscription instanceof DownloadableSubscription});
60 » else { //Update from previous versions 90 if (hasSubscriptions)
61 » » if(preferences.float('version') < 0.60) { //Updating from versi ons before Next, only enabled lists are ported 91 return;
62 » » » var enabledLists = new Array(); 92
63 » » » for(key in sources.all()) { //Notes all enabled lists 93 // Load subscriptions data
64 » » » » if(preferences.bool(key)) 94 var request = new XMLHttpRequest();
65 » » » » » enabledLists.push(key); 95 request.open("GET", "subscriptions.xml");
66 » » » } 96 request.onload = function()
67 » » » var enabledCss = new Array(); 97 {
68 » » » for(key in sources.css) { //Notes all enabled lists 98 var subscriptions = request.responseXML.documentElement.getElementsByTagName ("subscription");
69 » » » » if(preferences.bool(key)) 99 var selectedItem = null;
70 » » » » » enabledCss.push(key); 100 var selectedPrefix = null;
71 » » » } 101 var matchCount = 0;
72 » » » var whitelist = lists.whitelist.get(); 102 for (var i = 0; i < subscriptions.length; i++)
73 » » » 103 {
74 » » » widget.preferences.clear(); //Removes all old preference s 104 var subscription = subscriptions[i];
75 » » » 105 if (!selectedItem)
76 » » » for(i in enabledLists) { //Enable all previously enabled lists 106 selectedItem = subscription;
77 » » » » lists.enable(enabledLists[i]); 107
78 » » » } 108 var prefix = require("utils").Utils.checkLocalePrefixMatch(subscription.ge tAttribute("prefixes"));
79 » » » for(i in enabledCss) { //Enable all previously enabled l ists 109 if (prefix)
80 » » » » css.enable(enabledCss[i], false); 110 {
81 » » » } 111 if (!selectedPrefix || selectedPrefix.length < prefix.length)
82 » » » lists.whitelist.set(whitelist); 112 {
83 » » } 113 selectedItem = subscription;
84 » » else if(preferences.float('version') <= 0.71) { //Updating from versions before lists merge and change 114 selectedPrefix = prefix;
85 » » » widget.preferences.clear(); //Removes all old preference s 115 matchCount = 1;
86 » » » // As no stable version exist between 0.52 and 0.71, the settings are not ported and simply removed from the extension 116 }
87 » » } 117 else if (selectedPrefix && selectedPrefix.length == prefix.length)
88 » » 118 {
89 » } 119 matchCount++;
90 » //Updates the version 120
91 » preferences.string('version', window.widget.version); 121 // If multiple items have a matching prefix of the same length:
122 // Select one of the items randomly, probability should be the same
123 // for all items. So we replace the previous match here with
124 // probability 1/N (N being the number of matches).
125 if (Math.random() * matchCount < 1)
126 {
127 selectedItem = subscription;
128 selectedPrefix = prefix;
129 }
130 }
131 }
132 }
133
134 var subscription = (selectedItem ? Subscription.fromURL(selectedItem.getAttr ibute("url")) : null);
135 if (subscription)
136 {
137 subscription.disabled = false;
138 subscription.title = selectedItem.getAttribute("title");
139 subscription.homepage = selectedItem.getAttribute("homepage");
140 if (subscription instanceof DownloadableSubscription && !subscription.last Download)
141 Synchronizer.execute(subscription);
142 FilterStorage.addSubscription(subscription);
143 }
144 };
145 request.send(null);
92 } 146 }
93
94 function updateAll() {
95 //opera.postError('updateAll() called');
96 for(key in sources.css) {
97 if(css.status(key) && getTime() - css.time(key) > preferences.in t('interval')) { //If the list is enabled
98 css.update(key);
99 //opera.postError(key + ' updated');
100 }
101 }
102 for(key in sources.all()) {
103 if(lists.status(key) && getTime() - lists.time(key) > preference s.int('interval')) { //If the list is enabled
104 lists.update(key);
105 //opera.postError(key + ' updated');
106 }
107 }
108 window.setTimeout('updateAll()', preferences.int('interval') / 12); //Ve rifies required updates every 1/12 of the update interval
109 }
110
111 lists.setup(); //Enables all lists
112 updateAll(); //Sets update intervals
OLDNEW
« no previous file with comments | « no previous file | button.js » ('j') | button.js » ('J')

Powered by Google App Engine
This is Rietveld