Skip to content

Commit

Permalink
Added Hindi language; Cleaned code from old stuff; improved stats;
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Andryukhin committed Apr 21, 2015
1 parent a5d2a0c commit 2206b8f
Show file tree
Hide file tree
Showing 10 changed files with 908 additions and 373 deletions.
487 changes: 487 additions & 0 deletions _locales/hi/messages.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion background.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<script type="text/javascript" src="experiments.js"></script>
<script type="text/javascript" src="welcometips.js"></script>
<script type="text/javascript" src="surveys_core.js"></script>
<script type="text/javascript" src="payments.js"></script>
<script type="text/javascript" src="stats.js"></script>
<script type="text/javascript" src="background.js"></script>
</head>
<body>
Expand Down
116 changes: 76 additions & 40 deletions background.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
background.js
Copyright © 2009 - 2013 WOT Services Oy <info@mywot.com>
Copyright © 2009 - 2015 WOT Services Oy <info@mywot.com>
This file is part of WOT.
Expand All @@ -20,6 +20,7 @@

$.extend(wot, { core: {
usermessage: {},
fetching: false,
usercontent: [],
activity_score: 0,
badge_status: null,
Expand All @@ -29,6 +30,7 @@ $.extend(wot, { core: {
type: null,
text: ""
},
loc_map :{},
last_testimony: null, // datetime of the last testimony submitted

tags: {
Expand Down Expand Up @@ -904,6 +906,13 @@ $.extend(wot, { core: {
// }
},

fetch:function(tab) {
var port = chrome.tabs.connect(tab.id, { name: "warning" });
port.postMessage({
message: "loc:check"
});
},

onload: function()
{
try {
Expand All @@ -918,24 +927,28 @@ $.extend(wot, { core: {

wot.bind("message:search:hello", function(port, data) {

var lock_state = null,
unlock_price = null;

if (wot.payments) {
lock_state = wot.payments.get_feature_status("search-icons");
unlock_price = wot.payments.get_price("search-icons");
}

wot.core.processrules(data.url, function(rule) {
port.post("process", {
url: data.url,
rule: rule,
lock_state: lock_state,
unlock_price: unlock_price
rule: rule
});
});
});

wot.bind("message:search:check", function(port, data) {

if (data.top && data.visible != "prerender") { // analize only main window and ignore frames
try {
wot.stats.loc(data.url, data.referrer);
} catch (e) {
console.error('Exception in stats.loc captured:');
console.error(e);
}
}
wot.core.fetching = false;
});


wot.bind("message:search:get", function(port, data) {
wot.core.loadratings(data.targets, function(hosts) {
var ratings = {};
Expand Down Expand Up @@ -1019,24 +1032,6 @@ $.extend(wot, { core: {
wot.core.open_scorecard(data.target, data.ctx);
});

wot.bind("message:search:openunlocker", function(port, data) {
if (wot.payments) {
wot.payments.open_unlocker(data);
}
});

wot.bind("message:search:premium-tos", function(port, data) {
if (wot.payments) {
wot.payments.open_premium_tos(data);
}
});

wot.bind("message:search:premium-readmore", function(port, data) {
if (wot.payments) {
wot.payments.open_premium_readmore(data);
}
});

wot.bind("message:search:ratesite", function(port, data) {
wot.core.open_scorecard(data.target, data.ctx, "rate");
});
Expand All @@ -1047,12 +1042,6 @@ $.extend(wot, { core: {
});
});

wot.bind("message:my:payment_approved", function(port, data) {
window.setTimeout(function(){
wot.cache.clearall();
}, 300);
});

wot.bind("message:tags:clearmytags", function(port, data) {
wot.core.tags.expire_mytags();
});
Expand All @@ -1065,16 +1054,64 @@ $.extend(wot, { core: {
wot.wt.bind_events();
}

wot.listen([ "search", "my", "tab", "warnings", "tags", "wtb", "surveyswidget", "ads" ]);
wot.listen([ "search", "my", "tab", "warnings", "tags", "wtb", "surveyswidget" ]);

/* event handlers */

chrome.tabs.onUpdated.addListener(function(id, obj) {
chrome.tabs.onUpdated.addListener(function(id, changeInfo, tab) {
wot.core.updatetab(id, true);
if (changeInfo.status == 'complete') {
if(wot.stats.isWebURL(tab.url)) {
wot.core.loc_map[id] = tab.url;
wot.core.fetching = true;
wot.core.fetch(tab);
}
}
});

chrome.tabs.onReplaced.addListener(function(addedTabId, removedTabId){
wot.core.fetching = true;
var tab = chrome.tabs.get(addedTabId, function(tab) {
if(wot.stats.isWebURL(tab.url)) {
wot.core.loc_map[addedTabId] = tab.url;
if(typeof (wot.core.loc_map[removedTabId]) != 'undefined'){
delete wot.core.loc_map[removedTabId];
}
wot.core.fetch(tab);
}
});
});

chrome.tabs.onActivated.addListener(function(info) {
if(!wot.core.fetching) {
var tab = chrome.tabs.get(info.tabId, function(tab) {
if(wot.stats.isWebURL(tab.url)) {
if(typeof (wot.core.loc_map[info.tabId]) != 'undefined'){
wot.stats.focus(tab.url);
}

}
});
}
});

chrome.tabs.onSelectionChanged.addListener(function(id, obj) {
chrome.tabs.onSelectionChanged.addListener(function(id, selectInfo) {
wot.core.updatetab(id, true);
if(!wot.core.fetching) {
chrome.tabs.get(id, function(tab) {
if(wot.stats.isWebURL(tab.url)) {
if(typeof (wot.core.loc_map[id]) != 'undefined'){
wot.stats.focus(tab.url);
}
}
});
}
});

chrome.tabs.onRemoved.addListener(function(id, removeInfo) {
if(typeof (wot.core.loc_map[id]) != 'undefined'){
delete wot.core.loc_map[id];
}
});

wot.core.createmenu();
Expand All @@ -1097,7 +1134,6 @@ $.extend(wot, { core: {
wot.core.update(true);

if (wot.api.isregistered()) {
if (wot.payments) wot.payments.load_config(); // init paid features offer
wot.core.welcome_user();
wot.api.update();
wot.api.processpending(); // submit
Expand Down
68 changes: 3 additions & 65 deletions content/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,6 @@ const WOT_POPUP_HTML =
'<div class="wot-corners-wrapper">' +
'<div id="wot-pp-tr" class="wot-pp-tr"></div>' +
'<div id="wot-pp-cs" class="wot-pp-cs"></div>' +
'</div>' +
'<div id="wot-unlock">' +
'<div class="wot-unlock-icon"></div>' +
'<div class="wot-unlock-text">Help us make WOT better. We ask for a small fee of ${PRICE} / year to activate <b>safety icons</b>.</div>' +
'<div id="wot-unlock-btn">Activate using PayPal</div>' +
'<div id="wot-unlock-learnmore">Read more and tell us what you think <a id="wot-unlock-readmore">on our forum</a>.</div>' +
'<div id="wot-unlock-tos">By clicking "Activate" you agree with <a id="wot-unlock-toslink">terms of service</a>.</div>' +
'</div>';

wot.popup = {
Expand Down Expand Up @@ -121,11 +114,10 @@ wot.popup = {
this.rule_name = rule_name;

var layer = document.createElement("div");
var accessible_cls = wot.search.settings.accessible ? "wot-popup-layer-accessible" : "",
locked_cls = wot.search.is_unlocked() ? "" : "wot-locked";
var accessible_cls = wot.search.settings.accessible ? "wot-popup-layer-accessible" : "";

layer.setAttribute("id", id);
layer.setAttribute("class", [ "wot-popup-layer", accessible_cls, locked_cls ].join(" "));
layer.setAttribute("class", [ "wot-popup-layer", accessible_cls ].join(" "));
layer.setAttribute("style", "display: none;");


Expand All @@ -139,9 +131,6 @@ wot.popup = {
}, {
from: "POPUPNOCAT",
to: wot.i18n("popup", "nocattext")
}, {
from: "PRICE",
to: wot.utils.htmlescape(String(wot.search.unlock_price))
}
];

Expand All @@ -166,21 +155,6 @@ wot.popup = {
rate_link.addEventListener("click", wot.popup.on_rate_click);
}

var unlock_button = document.getElementById("wot-unlock-btn");
if (unlock_button) {
unlock_button.addEventListener("click", wot.popup.on_unlock_click);
}

var tos_link = document.getElementById("wot-unlock-toslink");
if (tos_link) {
tos_link.addEventListener("click", wot.popup.on_unlock_tos_click);
}

var read_link = document.getElementById("wot-unlock-readmore");
if (read_link) {
read_link.addEventListener("click", wot.popup.on_unlock_read_click);
}

} catch (e) {
console.error("popup.add: failed with " + e);
}
Expand Down Expand Up @@ -644,42 +618,6 @@ wot.popup = {
} catch (e) {
console.error("popup.onclick: failed with ", e);
}
},

on_unlock_click: function (event) {
event.preventDefault();
event.stopPropagation();

wot.post("search", "openunlocker",
{
ctx: wot.urls.contexts.popupviewsc,
rule: wot.popup.rule_name
});

wot.popup.hide(wot.popup.version, true);
},

on_unlock_tos_click: function (event) {
event.preventDefault();
event.stopPropagation();

wot.post("search", "premium-tos",
{
ctx: wot.urls.contexts.popupviewsc,
rule: wot.popup.rule_name
});

// wot.popup.hide(wot.popup.version, true);
},

on_unlock_read_click: function (event) {
event.preventDefault();
event.stopPropagation();
}

wot.post("search", "premium-readmore",
{
ctx: wot.urls.contexts.popupviewsc,
rule: wot.popup.rule_name
});
}
};
Loading

0 comments on commit 2206b8f

Please sign in to comment.