Skip to content

Commit

Permalink
Merge pull request #11 from ety001/3.0.2
Browse files Browse the repository at this point in the history
3.0.2
  • Loading branch information
ety001 authored Feb 4, 2020
2 parents d0650b2 + 4a385b3 commit fbfd7f4
Show file tree
Hide file tree
Showing 11 changed files with 141 additions and 91 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "review-bookmark",
"version": "3.0.1",
"version": "3.0.2",
"description": "A bookmark manager for Chrome.",
"author": "ETY001 <[email protected]>",
"license": "MIT",
Expand Down
6 changes: 6 additions & 0 deletions src/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,11 @@
},
"clear_block_list": {
"message": "Clear List"
},
"ga": {
"message": "Whether to enable Data Analyzes? This will help author improve the extension's experience."
},
"enable": {
"message": "Enable"
}
}
6 changes: 6 additions & 0 deletions src/_locales/zh_CN/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,11 @@
},
"clear_block_list": {
"message": "清空列表"
},
"ga": {
"message": "是否允许作者统计数据以此提升使用体验"
},
"enable": {
"message": "激活"
}
}
56 changes: 30 additions & 26 deletions src/background.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import store from './store';
import * as types from './store/mutation-types';
import * as BookmarkLib from './libs/BookmarkLib';
import { GA } from './libs/GA';

global.browser = require('webextension-polyfill');

Expand Down Expand Up @@ -35,29 +36,6 @@ chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
}
});

//google analytics
const currentVersion = '3_0_1';
const gaID = 'UA-64832923-4';
(function(i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
(i[r] =
i[r] ||
function() {
(i[r].q = i[r].q || []).push(arguments);
}),
(i[r].l = 1 * new Date());
(a = s.createElement(o)), (m = s.getElementsByTagName(o)[0]);
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m);
})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');
ga('create', gaID, 'auto');
ga('set', 'checkProtocolTask', function() {});
ga('require', 'displayfeatures');
function sendEvent(eventCategory, eventAction, eventLabel = '', eventValue = '') {
ga('send', 'event', eventCategory, eventAction, eventLabel, eventValue);
}

// 生成uid
const RandomStr = function(len) {
len = len || 32;
Expand All @@ -77,13 +55,32 @@ const GetUid = {
var d = new Date();
var uid = RandomStr() + d.getSeconds() + d.getMinutes() + d.getMilliseconds();
window.localStorage.uid = uid;
sendEvent(currentVersion, 'create_user', uid);
}
return uid;
},
};
const uid = GetUid.get();

//google analytics
let currentVersion = '3_0_2';
if (isChrome) {
currentVersion = `chrome_${currentVersion}`;
}
if (isFirefox) {
currentVersion = `firefox_${currentVersion}`;
}
const gaID = 'UA-64832923-4';
const gaObj = new GA(gaID, uid);
function sendEvent(eventCategory, eventAction, eventLabel = '', eventValue = '') {
if (store.getters.config.ga === false) return;
gaObj.ga('event', eventCategory, eventAction, eventLabel, eventValue);
}
// dh -- Document hostname, dp -- Page, dt -- Title
function sendPageview(dp, dh = '', dt = '') {
if (store.getters.config.ga === false) return;
gaObj.ga('pageview', dh, dp, dt);
}

//数据初始化
BookmarkLib.init();

Expand All @@ -100,6 +97,7 @@ chrome.runtime.onConnect.addListener(function(port) {
return;
}
const bmForFull = BookmarkLib.getBookmark();
sendPageview('/full_mode_page');
sendEvent(currentVersion, 'getbookmark_from_full', 'get_bookmark_' + uid, JSON.stringify({ uid, bmForFull }));
port.postMessage({ ctype: ctype, cdata: bmForFull });
break;
Expand All @@ -109,6 +107,7 @@ chrome.runtime.onConnect.addListener(function(port) {
return;
}
const bmForMini = BookmarkLib.getBookmark();
sendPageview('/mini_mode_notification');
sendEvent(currentVersion, 'getbookmark_from_mini', 'get_bookmark_' + uid, JSON.stringify({ uid, bmForMini }));
port.postMessage({
ctype,
Expand Down Expand Up @@ -146,6 +145,7 @@ chrome.runtime.onConnect.addListener(function(port) {
break;
case 'getbookmark_menu':
BookmarkLib.getBookmarkMenu(menu => {
sendPageview('/bookmark_manager_page');
sendEvent(currentVersion, 'getbookmark_menu', 'getbookmark_menu_' + uid, JSON.stringify({ uid }));
port.postMessage({ ctype, cdata: menu });
});
Expand Down Expand Up @@ -180,6 +180,7 @@ chrome.runtime.onConnect.addListener(function(port) {
});
break;
case 'get_config':
sendPageview('/popup');
sendEvent(currentVersion, 'get_config', 'get_config_' + uid, JSON.stringify({ uid, config: store.getters.config }));
port.postMessage({ ctype, cdata: store.getters.config });
break;
Expand All @@ -191,6 +192,7 @@ chrome.runtime.onConnect.addListener(function(port) {
random: cdata.random,
frequency: cdata.frequency,
currentNotifyLocation: cdata.currentNotifyLocation,
ga: cdata.ga,
});
port.postMessage({ ctype, cdata: true });
break;
Expand All @@ -203,6 +205,7 @@ chrome.runtime.onConnect.addListener(function(port) {
});
break;
case 'get_block_list':
sendPageview('/block_list_page');
sendEvent(currentVersion, 'get_block_list', 'get_block_list_' + uid, JSON.stringify({ uid }));
BookmarkLib.getBlockList(blockedBookmarks => {
port.postMessage({ ctype, cdata: blockedBookmarks });
Expand Down Expand Up @@ -245,6 +248,9 @@ chrome.bookmarks.onRemoved.addListener((id, removeInfo) => {
chrome.runtime.onInstalled.addListener(detail => {
if (detail.reason == 'update') {
sendEvent(currentVersion, 'update_extension', uid, '');
// 弹出推广页面
window.open('https://creatorsdaily.com/9999e88d-0b00-46dc-8ff1-e1d311695324');
return;
chrome.notifications.create(
{
type: 'basic',
Expand All @@ -254,8 +260,6 @@ chrome.runtime.onInstalled.addListener(detail => {
},
function(notification_id) {}
);
// 弹出推广页面
window.open('https://creatorsdaily.com/9999e88d-0b00-46dc-8ff1-e1d311695324');
}
if (detail.reason === 'install') {
sendEvent(currentVersion, 'install_extension', uid, '');
Expand Down
60 changes: 0 additions & 60 deletions src/libs/ChromeStorage.js

This file was deleted.

34 changes: 34 additions & 0 deletions src/libs/GA.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
export class GA {
constructor(ua, cid) {
this.ua = ua;
this.cid = cid; // client id
this.gaApi = 'https://www.google-analytics.com/collect';
this.version = '1';
}
ga(t, ...items) {
let payload = `v=${this.version}&tid=${this.ua}&cid=${this.cid}`;
let params = [];
switch (t) {
case 'pageview': // Pageview hit type
// dh -- Document hostname
// dp -- Page
// dt -- Title
params = ['dh', 'dp', 'dt'];
break;
case 'event':
// ec -- Event Category. Required
// ea -- Event Action. Required
// el -- Event label.
// ev -- Event value.
params = ['ec', 'ea', 'el', 'ev'];
}
if (params === []) return;
payload = `${payload}&t=${t}`;
items.forEach((v, i) => {
payload = `${payload}&${params[i]}=${encodeURIComponent(v)}`;
});
const request = new XMLHttpRequest();
request.open('POST', this.gaApi, true);
request.send(payload);
}
}
33 changes: 33 additions & 0 deletions src/manifest.firefox.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "__MSG_appname__",
"description": "__MSG_appdesc__",
"version": null,
"manifest_version": 2,
"default_locale": "en",
"author": "ETY001",
"homepage_url": "https://creatorsdaily.com/9999e88d-0b00-46dc-8ff1-e1d311695324",
"icons": {
"16": "icons/icon-16.png",
"19": "icons/icon-19.png",
"38": "icons/icon-38.png",
"48": "icons/icon-48.png",
"128": "icons/icon-128.png"
},
"browser_action": {
"default_title": "__MSG_appname__",
"default_popup": "popup/popup.html"
},
"background": {
"scripts": ["background.js"]
},
"content_scripts": [
{
"matches": ["*://*/*"],
"css": ["content-script/content-script.css"],
"js": ["content-script/cs-init.js", "content-script/content-script.js"],
"run_at": "document_end"
}
],
"web_accessible_resources": ["tab/tab.html", "fonts/*", "bookmark/bookmark.html"],
"permissions": ["notifications", "bookmarks", "tabs", "storage", "unlimitedStorage", "https://www.google-analytics.com/"]
}
3 changes: 1 addition & 2 deletions src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"run_at": "document_end"
}
],
"content_security_policy": "script-src 'self' https://www.google-analytics.com; object-src 'self'",
"web_accessible_resources": ["tab/tab.html", "fonts/*", "bookmark/bookmark.html"],
"permissions": ["notifications", "bookmarks", "tabs", "background", "storage", "unlimitedStorage"]
"permissions": ["notifications", "bookmarks", "tabs", "background", "storage", "unlimitedStorage", "https://www.google-analytics.com/"]
}
29 changes: 28 additions & 1 deletion src/popup/App.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
<template>
<div>
<el-row class="config-box" v-if="formData !== null">
<el-col :span="24">
<el-col :span="24" v-if="ga === false">
<h4>{{ 'ga' | lang }}</h4>
<el-form>
<el-form-item>
<el-button type="primary" @click="enableGa()">{{ 'confirm_btn' | lang }}</el-button>
<el-button type="warning" @click="cancelGa()">{{ 'cancel_btn' | lang }}</el-button>
</el-form-item>
</el-form>
</el-col>
<el-col :span="24" v-if="ga === true">
<el-form ref="form1" :rules="rules" :model="formData" label-position="left" label-width="140px" @submit.native.prevent>
<el-form-item :label="'switch' | lang" prop="status">
<el-switch v-model="formData.status"></el-switch>
Expand All @@ -20,6 +29,12 @@
<el-option v-for="(item, idx) in notifyLocation" :key="idx" :label="item.name" :value="item.val"></el-option>
</el-select>
</el-form-item>
<el-form-item label="" prop="ga" size="mini" label-width="0">
<el-checkbox-group v-model="formData.ga">
<el-checkbox :label="'ga' | lang" name="ga"></el-checkbox>
</el-checkbox-group>
</el-form-item>

<el-form-item>
<el-button type="primary" @click="save('form1')">{{ 'save' | lang }}</el-button>
<el-button type="warning" @click="blockManager()">{{ 'block_manager' | lang }}</el-button>
Expand All @@ -43,6 +58,7 @@ export default {
};
return {
formData: null,
ga: false,
notifyLocation: [
{
name: this.getLang('top_right'),
Expand All @@ -65,6 +81,7 @@ export default {
status: [{ type: 'boolean', message: 'need boolean', trigger: 'change' }],
mini: [{ type: 'boolean', message: 'need boolean', trigger: 'change' }],
random: [{ type: 'boolean', message: 'need boolean', trigger: 'change' }],
ga: [{ type: 'boolean', message: 'need boolean', trigger: 'change' }],
frequency: [{ type: 'integer', message: this.getLang('need_integer'), trigger: 'blur' }],
currentNotifyLocation: [{ validator: validateNotifyPosition, trigger: 'change' }],
},
Expand All @@ -76,6 +93,13 @@ export default {
if (!val) return '';
return chrome.i18n.getMessage(val);
},
enableGa() {
this.formData.ga = true;
this.port.postMessage({ ctype: 'save_config', cdata: this.formData });
},
cancelGa() {
this.ga = true;
},
save(formName) {
this.$refs[formName].validate(valid => {
if (!valid) {
Expand Down Expand Up @@ -109,6 +133,7 @@ export default {
type: 'success',
message: this.getLang('save_success'),
});
this.ga = true;
break;
case 'get_config':
this.formData = {
Expand All @@ -117,7 +142,9 @@ export default {
random: msg.cdata.random,
frequency: msg.cdata.frequency,
currentNotifyLocation: msg.cdata.currentNotifyLocation,
ga: msg.cdata.ga,
};
this.ga = msg.cdata.ga;
break;
}
});
Expand Down
1 change: 1 addition & 0 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default new Vuex.Store({
random: true, // 随机展示
frequency: 5, // mini 模式展示频度
currentNotifyLocation: 'top-right', // 当前 Mini 提醒框位置
ga: false, // Google Analytics Status
},
frequencyCounter: 0, // mini模式展示频度计数器
waitingBookmarks: [], // 所有待提醒书签
Expand Down
Loading

0 comments on commit fbfd7f4

Please sign in to comment.