Skip to content

Commit

Permalink
remove sogou related code from chrome extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Bo Zhu committed Jul 7, 2014
1 parent 5f7e917 commit 585ed4c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 72 deletions.
16 changes: 7 additions & 9 deletions chrome/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
*/

/*jslint browser: true */
/*global chrome: false, get_storage: false, set_storage: false, new_random_ip: false, new_sogou_auth_str: false */
/*global setup_lite_header: false, setup_redirect: false, setup_normal_header: false, setup_proxy: false, setup_timezone: false, setup_extra_header: false */
/*global clear_lite_header: false, clear_redirect: false, clear_normal_header: false, clear_proxy: false, clear_timezone: false */
/*global chrome: false, get_storage: false, set_storage: false, new_random_ip: false */
/*global setup_redirect: false, setup_header: false, setup_proxy: false, setup_timezone: false, setup_extra_header: false */
/*global clear_redirect: false, clear_header: false, clear_proxy: false, clear_timezone: false */
/*global ga_report_event: false, ga_report_ratio: false, ga_report_error: false */
"use strict";

Expand All @@ -40,8 +40,6 @@ unblock_youku.header_extra_url_list = [

unblock_youku.ip_addr = new_random_ip();
console.log('ip addr: ' + unblock_youku.ip_addr);
unblock_youku.sogou_auth = new_sogou_auth_str();
console.log('sogou_auth: ' + unblock_youku.sogou_auth);

unblock_youku.version = chrome.runtime.getManifest().version;
// the lastest version to show NEW on the icon; it's usually a big update with new features
Expand Down Expand Up @@ -93,7 +91,7 @@ function clear_mode_settings(mode_name) {
switch (mode_name) {
case 'lite':
// clear_timezone();
clear_lite_header();
clear_header();
console.log('cleared settings for lite');
break;
case 'redirect':
Expand All @@ -103,7 +101,7 @@ function clear_mode_settings(mode_name) {
case 'normal':
// clear_timezone();
clear_proxy();
clear_normal_header();
clear_header();
console.log('cleared settings for normal');
break;
default:
Expand All @@ -119,14 +117,14 @@ function clear_mode_settings(mode_name) {
function setup_mode_settings(mode_name) {
switch (mode_name) {
case 'lite':
setup_lite_header();
setup_header();
// setup_timezone();
break;
case 'redirect':
setup_redirect();
break;
case 'normal':
setup_normal_header();
setup_header();
setup_proxy();
// setup_timezone();
break;
Expand Down
74 changes: 13 additions & 61 deletions chrome/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/*global chrome: false, unblock_youku: false, compute_sogou_tag: false */
/*global chrome: false, unblock_youku: false */
/*global ga_report_error: false */
"use strict";

function lite_header_modifier(details) {
details.requestHeaders.push({
name: 'X-Forwarded-For',
value: unblock_youku.ip_addr
}, {
name: 'Client-IP',
value: unblock_youku.ip_addr
});

return {requestHeaders: details.requestHeaders};
}

function normal_header_modifier(details) {
var timestamp = Math.round(details.timeStamp / 1000).toString(16);
var tag = compute_sogou_tag(timestamp, details.url);

console.log('t=' + timestamp + ' h=' + tag + ' ' + details.url);
function header_modifier(details) {
console.log('Modify headers of ' + details.url);

details.requestHeaders.push({
name: 'X-Sogou-Auth',
value: unblock_youku.sogou_auth
}, {
name: 'X-Sogou-Timestamp',
value: timestamp
}, {
name: 'X-Sogou-Tag',
value: tag
}, {
name: 'X-Forwarded-For',
value: unblock_youku.ip_addr
}, {
Expand All @@ -58,56 +35,31 @@ function normal_header_modifier(details) {
return {requestHeaders: details.requestHeaders};
}

function setup_lite_header() {
if (!chrome.webRequest.onBeforeSendHeaders.hasListener(lite_header_modifier)) {
chrome.webRequest.onBeforeSendHeaders.addListener(
lite_header_modifier,
{urls: unblock_youku.normal_url_list}, // the same url list as normal mode
['requestHeaders', 'blocking']
);
console.log('lite_header_modifier is set');
} else {
var err_msg = 'lite_header_modifier is already there!';
console.error(err_msg);
ga_report_error('Unexpected Error', err_msg);
}
}

function setup_normal_header() {
if (!chrome.webRequest.onBeforeSendHeaders.hasListener(normal_header_modifier)) {
function setup_header() {
if (!chrome.webRequest.onBeforeSendHeaders.hasListener(header_modifier)) {
chrome.webRequest.onBeforeSendHeaders.addListener(
normal_header_modifier,
header_modifier,
{
urls: unblock_youku.normal_url_list
},
['requestHeaders', 'blocking']
);
console.log('normal_header_modifier is set');
console.log('header_modifier is set');
} else {
var err_msg = 'normal_header_modifer is already there!';
var err_msg = 'header_modifer is already there!';
console.error(err_msg);
ga_report_error('Unexpected Error', err_msg);
}
}


function clear_lite_header() {
if (chrome.webRequest.onBeforeSendHeaders.hasListener(lite_header_modifier)) {
chrome.webRequest.onBeforeSendHeaders.removeListener(lite_header_modifier);
console.log('lite_header_modifier is removed');
} else {
var err_msg = 'lite_header_modifer is not there!';
console.error(err_msg);
ga_report_error('Unexpected Error', err_msg);
}
}

function clear_normal_header() {
if (chrome.webRequest.onBeforeSendHeaders.hasListener(normal_header_modifier)) {
chrome.webRequest.onBeforeSendHeaders.removeListener(normal_header_modifier);
console.log('normal_header_modifier is removed');
function clear_header() {
if (chrome.webRequest.onBeforeSendHeaders.hasListener(header_modifier)) {
chrome.webRequest.onBeforeSendHeaders.removeListener(header_modifier);
console.log('header_modifier is removed');
} else {
var err_msg = 'normal_header_modifier is not there!';
var err_msg = 'header_modifier is not there!';
console.error(err_msg);
ga_report_error('Unexpected Error', err_msg);
}
Expand Down
3 changes: 1 addition & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Unblock Youku",
"version": "2.7.4.0",
"version": "2.7.4.1",
"manifest_version": 2,
"minimum_chrome_version": "25.0",
"description": "__MSG_description__",
Expand All @@ -21,7 +21,6 @@
"scripts": [
"shared/urls.js",
"shared/tools.js",
"shared/sogou.js",
"chrome/pages/js/analytics.js",
"chrome/storage.js",
"chrome/header.js",
Expand Down

0 comments on commit 585ed4c

Please sign in to comment.