Skip to content

Commit

Permalink
Deprecate the redirect mode and its code
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuzhuor committed Jun 29, 2022
1 parent dac2abf commit 8776523
Show file tree
Hide file tree
Showing 14 changed files with 78 additions and 391 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"browser": true,
"webextensions": true,
"node": true,
"jquery": true,
"es2021": true
},
"extends": [
Expand Down
6 changes: 3 additions & 3 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@
"message": "https://www.uku.im/index.html"
},
"support_title": {
"message": "We Need Your Support"
"message": "We Need Your Donation"
},
"support_message": {
"message": "Please support us to make Unblock Youku better."
"message": "Please donate to us to make Unblock Youku more usable."
},
"support_button": {
"message": "<i class=\"fa fa-heart\" aria-hidden=\"true\"></i> Please Support Us"
"message": "<i class=\"fa fa-heart\" aria-hidden=\"true\"></i> Donate to us <i class=\"fa fa-heart\" aria-hidden=\"true\"></i>"
}
}
4 changes: 2 additions & 2 deletions _locales/zh_CN/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@
"message": "https://www.uku.im/index.html"
},
"support_title": {
"message": "我们需要您的支持"
"message": "我们需要您的捐款"
},
"support_message": {
"message": "请帮助 Unblock Youku 长久稳定和免费地运行下去"
},
"support_button": {
"message": "<i class=\"fa fa-heart\" aria-hidden=\"true\"></i> 请支持我们"
"message": "<i class=\"fa fa-heart\" aria-hidden=\"true\"></i> 向我们捐款 <i class=\"fa fa-heart\" aria-hidden=\"true\"></i>"
}
}
4 changes: 2 additions & 2 deletions _locales/zh_TW/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@
"message": "https://www.uku.im/index_zht.html"
},
"support_title": {
"message": "我們需要您的支持"
"message": "我們需要您的捐款"
},
"support_message": {
"message": "請幫助 Unblock Youku 長久穩定和免費地運行下去"
},
"support_button": {
"message": "<i class=\"fa fa-heart\" aria-hidden=\"true\"></i> 請支持我們"
"message": "<i class=\"fa fa-heart\" aria-hidden=\"true\"></i> 向我們捐款 <i class=\"fa fa-heart\" aria-hidden=\"true\"></i>"
}
}
132 changes: 54 additions & 78 deletions chrome/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,23 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/*global setup_redirect: false, setup_header: false, setup_proxy: false */
/*global setup_header: false, setup_proxy: false */
/*global clear_redirect: false, clear_header: false, clear_proxy: false */
/*global ga_report_event: false, ga_report_ratio: false, ga_report_error: false */
"use strict";

// ====== Constant and Variable Settings ======
var unblock_youku = unblock_youku || {}; // namespace

// only for proxy mode
// Default proxy server settings
unblock_youku.default_proxy_server_proc = 'HTTPS';
unblock_youku.default_proxy_server_addr = 'secure.uku.im:8443';
unblock_youku.backup_proxy_server_proc = 'HTTPS';
unblock_youku.backup_proxy_server_addr = 'secure.uku.im:993';

// only for redirect mode
unblock_youku.default_redirect_server = 'www.yōukù.com/proxy';
unblock_youku.backup_redirect_server = 'bak.yōukù.com/proxy';

unblock_youku.ip_addr = new_random_ip();
console.log('ip addr: ' + unblock_youku.ip_addr);
console.log('generated random ip addr: ' + unblock_youku.ip_addr);


// ====== Configuration Functions ======
Expand All @@ -45,7 +42,7 @@ function set_mode_name(mode_name, callback) {
ga_report_error('Unexpected Error', err_msg);
}

if (mode_name === 'off' || mode_name === 'lite') {
if (mode_name === 'off') {
set_storage('unblock_youku_mode', mode_name, callback);
} else {
set_storage('unblock_youku_mode', 'normal', callback);
Expand All @@ -60,10 +57,8 @@ function get_mode_name(callback) {
}

get_storage('unblock_youku_mode', function(current_mode) {
if (typeof current_mode === 'undefined' || (
current_mode !== 'off' &&
current_mode !== 'lite' )) {
set_mode_name('normal', function() {
if (typeof current_mode === 'undefined' || current_mode !== 'off') {
set_mode_name('normal', function () {
callback('normal');
});
} else {
Expand All @@ -74,54 +69,48 @@ function get_mode_name(callback) {

function clear_mode_settings(mode_name) {
switch (mode_name) {
case 'off':
console.log('cleared settings for off');
break;
case 'lite':
clear_header();
clear_redirect();
console.log('cleared settings for lite');
break;
case 'normal':
clear_header();
clear_proxy();
console.log('cleared settings for normal');
break;
default:
var err_msg = 'clear_mode_settings: should never come here';
console.error(err_msg);
ga_report_error('Unexpected Error', err_msg);
break;
case 'off':
console.log('cleared settings for off');
break;
case 'normal':
clear_header();
clear_redirect();
clear_proxy();
console.log('cleared settings for normal');
break;
default:
var err_msg = 'clear_mode_settings: should never come here';
console.error(err_msg);
ga_report_error('Unexpected Error', err_msg);
break;
}

console.log('cleared the settings for the mode: ' + mode_name);
}

function setup_mode_settings(mode_name) {
switch (mode_name) {
case 'off':
chrome.browserAction.setBadgeText({text: 'OFF'});
chrome.browserAction.setTitle({title: 'Unblock Youku has been turned off.'});
change_browser_icon('off');
break;
case 'lite':
setup_header();
setup_redirect();
chrome.browserAction.setBadgeText({text: 'LITE'});
chrome.browserAction.setTitle({title: 'Unblock Youku is running in the lite mode.'});
change_browser_icon('off');
break;
case 'normal':
// setup_header();
setup_proxy();
chrome.browserAction.setBadgeText({text: ''});
change_browser_icon('normal');
break;
default:
var err_msg = 'setup_mode_settings: should never come here';
console.error(err_msg);
ga_report_error('Unexpected Error', err_msg);
break;
case 'off':
chrome.browserAction.setBadgeText({ text: 'OFF' });
chrome.browserAction.setTitle({ title: 'Unblock Youku has been turned off.' });
change_browser_icon('off');
break;
case 'lite':
set_mode_name('normal', function() {
console.log('migrate lite mode to normal mode');
});
// fall through
case 'normal':
setup_header();
setup_proxy();
chrome.browserAction.setBadgeText({ text: '' });
change_browser_icon('normal');
break;
default:
var err_msg = 'setup_mode_settings: should never come here';
console.error(err_msg);
ga_report_error('Unexpected Error', err_msg);
break;
}

console.log('initialized the settings for the mode: ' + mode_name);
Expand All @@ -139,23 +128,23 @@ function change_browser_icon(option) {
var d = today.getDate();
var m = today.getMonth() + 1;

// hard-coded spring festivals
// hard-coded spring festival dates
var is_spring = false;
switch (y) {
case 2016: // February 8, 2016
if ((m === 1 && d >= 29) || (m === 2 && d <= 18)) {
is_spring = true;
}
case 2023: // Jan. 22, 2023
is_spring = m === 1;
break;
case 2024: // Feb. 10, 2024
is_spring = m === 2;
break;
case 2017: // January 28, 2017
if ((m === 1 && d >= 18) || (m === 2 && d <= 7)) {
is_spring = true;
}
case 2025: // Jan. 29, 2025
is_spring = m === 1;
break;
case 2018: // February 16, 2018
if (m === 2 && (6 <= d && d <= 26)) {
is_spring = true;
}
case 2026: // Feb. 17, 2026
is_spring = m === 2;
break;
case 2027: // Feb. 7, 2027
is_spring = m === 2;
break;
}
if (is_spring) {
Expand Down Expand Up @@ -209,19 +198,6 @@ function storage_monitor(changes, area) {
}
}

if (typeof changes.custom_redirect_server !== 'undefined') {
var redirect_server_change = changes.custom_redirect_server;

if (typeof redirect_server_change.newValue !== 'undefined') {
// have to use a localStorage cache for using in the blocking webRequest listener
localStorage.custom_redirect_server = redirect_server_change.newValue;
} else {
if (typeof localStorage.custom_redirect_server !== 'undefined') {
localStorage.removeItem('custom_redirect_server');
}
}
}

if (typeof changes.custom_proxy_server !== 'undefined') {
var proxy_server_change = changes.custom_proxy_server;
if (typeof proxy_server_change.newValue !== 'undefined'
Expand Down
11 changes: 5 additions & 6 deletions chrome/pages/js/options-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/*global chrome: false, $: false, localStorage: false */

var background = background || chrome.extension.getBackgroundPage();
var default_proxy_server_proc = background.unblock_youku.default_proxy_server_proc;
var default_proxy_server_addr = background.unblock_youku.default_proxy_server_addr;
Expand Down Expand Up @@ -79,6 +77,7 @@ function get_custom_proxy_server(callback) {

function test_custom_proxy_server(callback) {
"use strict";
// TODO: Change this URL to a new one. It stopped working a while ago.
var test_url = 'http://ipservice.163.com/isFromMainland';
show_proxy_test_message('info', 'Testing connection & Unblock...');
$.get(test_url, function(data) {
Expand Down Expand Up @@ -131,12 +130,12 @@ $(document).ready(function() {
background.setup_proxy();
$('#custom_proxy_reset').attr('disabled', false);
show_proxy_message('info', 'Enabled custom proxy server.');
test_custom_proxy_server();
// test_custom_proxy_server();
} else {
background.set_mode_name('normal', function() {
$('#custom_proxy_reset').attr("disabled", false);
show_proxy_message('warning', 'Enabled custom proxy server, and changed to proxy mode.');
test_custom_proxy_server();
// test_custom_proxy_server();
});
}
});
Expand All @@ -154,14 +153,14 @@ $(document).ready(function() {
$('#custom_proxy_addr').attr('disabled', false);
$('#custom_proxy_enable').attr('disabled', false);
show_proxy_message('warning', 'Reset custom proxy server.');
test_custom_proxy_server();
// test_custom_proxy_server();
} else {
background.set_mode_name('normal', function() {
$('#custom_proxy_proc').attr('disabled', false);
$('#custom_proxy_addr').attr('disabled', false);
$('#custom_proxy_enable').attr('disabled', false);
show_proxy_message('warning', 'Reset custom proxy server, and changed to proxy mode.');
test_custom_proxy_server();
// test_custom_proxy_server();
});
}
});
Expand Down
Loading

0 comments on commit 8776523

Please sign in to comment.