Skip to content

Commit

Permalink
fix setting lost by replacing storage.local with sync
Browse files Browse the repository at this point in the history
  • Loading branch information
niu541412 committed Jun 15, 2024
1 parent 509e213 commit 004219d
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 103 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 2.5.1
- 修复改成跨浏览器同步数据后会丢失配置

# 2.5.0
- 添加语言本地化(简体中文、繁体中文、英文)

Expand Down
2 changes: 1 addition & 1 deletion _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"message": "Easy Switch"
},
"description": {
"message": "Easily switching between websites, retaining search content for continued searching. You can switch using buttons or shortcuts. Supports custom search websites. Ported from a discontinued Chrome extension with the same name."
"message": "Easily switching between websites, retaining search content for continued searching. You can switch using buttons or shortcuts."
},
"noswitch": {
"message": "No switch"
Expand Down
202 changes: 101 additions & 101 deletions js/builtin.js
Original file line number Diff line number Diff line change
@@ -1,134 +1,134 @@
const Baidu = new SearchSite({
name: 'Baidu',
icon: 'icon/baidu.png',
tip: '百度一下',
home: 'https://www.baidu.com/',
searchUrl: 'https://www.baidu.com/s?wd=%s',
matches: ['//[\\w]*\\.baidu\\.com'],
exclude: ['//(video|v|baike)\\.baidu\\.com'],
types: [{
type: 'news',
home: 'http://news.baidu.com/',
searchUrl: 'http://news.baidu.com/ns?word=%s',
}]
name: 'Baidu',
icon: 'icon/baidu.png',
tip: '百度一下',
home: 'https://www.baidu.com/',
searchUrl: 'https://www.baidu.com/s?wd=%s',
matches: ['//[\\w]*\\.baidu\\.com'],
exclude: ['//(video|v|baike)\\.baidu\\.com'],
types: [{
type: 'news',
home: 'http://news.baidu.com/',
searchUrl: 'http://news.baidu.com/ns?word=%s',
}]
});
const Bing = new SearchSite({
name: 'Bing',
icon: 'icon/bing.png',
home: 'https://cn.bing.com/',
matches: ['//www\\.bing\\.com', '//cn\\.bing\\.com'],
searchUrl: 'https://cn.bing.com/search?q=%s',
types: [{
type: 'news',
home: 'https://cn.bing.com/news',
searchUrl: 'https://cn.bing.com/news/search?q=%s',
}]
name: 'Bing',
icon: 'icon/bing.png',
home: 'https://cn.bing.com/',
matches: ['//www\\.bing\\.com', '//cn\\.bing\\.com'],
searchUrl: 'https://cn.bing.com/search?q=%s',
types: [{
type: 'news',
home: 'https://cn.bing.com/news',
searchUrl: 'https://cn.bing.com/news/search?q=%s',
}]
});
const Google = new SearchSite({
name: 'Google',
icon: 'icon/google.png',
home: 'https://www.google.com/',
searchUrl: 'https://www.google.com/search?newwindow=1&hl=zh-CN&q=%s',
matches: ['//[\\w]*\\.google\\.'],
exclude: ['chrome\\.google\\.com'],
types: [{
type: 'news',
home: 'https://news.google.com/nwshp?hl=zh-CN',
searchUrl: 'https://www.google.com/search?q=%s&newwindow=1&tbm=nws&hl=zh-CN',
typeRegexp: '(news\\.google\\.com|\\.google\\.com.*?\\Wtbm=nws)',
}]
name: 'Google',
icon: 'icon/google.png',
home: 'https://www.google.com/',
searchUrl: 'https://www.google.com/search?newwindow=1&hl=zh-CN&q=%s',
matches: ['//[\\w]*\\.google\\.'],
exclude: ['chrome\\.google\\.com'],
types: [{
type: 'news',
home: 'https://news.google.com/nwshp?hl=zh-CN',
searchUrl: 'https://www.google.com/search?q=%s&newwindow=1&tbm=nws&hl=zh-CN',
typeRegexp: '(news\\.google\\.com|\\.google\\.com.*?\\Wtbm=nws)',
}]
});
const Youku = new SearchSite({
name: 'Youku',
icon: 'icon/youku.png',
home: 'http://www.youku.com/',
searchUrl: 'http://www.soku.com/v?keyword=%s',
matches: ['www\\.soku\\.com']
name: 'Youku',
icon: 'icon/youku.png',
home: 'http://www.youku.com/',
searchUrl: 'http://www.soku.com/v?keyword=%s',
matches: ['www\\.soku\\.com']
});
const Douyin = new SearchSite({
name: 'Douyin',
icon: 'icon/douyin.png',
home: 'https://www.douyin.com/',
searchUrl: 'https://www.douyin.com/search/%s',
matches: ['www\\.douyin\\.com']
name: 'Douyin',
icon: 'icon/douyin.png',
home: 'https://www.douyin.com/',
searchUrl: 'https://www.douyin.com/search/%s',
matches: ['www\\.douyin\\.com']
});
const BaiduVideo = new SearchSite({
name: 'BaiduVideo',
icon: 'icon/haokan.png',
home: 'http://v.baidu.com/',
matches: ['//(video|v)\\.baidu\\.com'],
searchUrl: 'http://v.baidu.com/v?word=%s&ie=utf-8'
name: 'BaiduVideo',
icon: 'icon/haokan.png',
home: 'http://v.baidu.com/',
matches: ['//(video|v)\\.baidu\\.com'],
searchUrl: 'http://v.baidu.com/v?word=%s&ie=utf-8'
});
const BaiduBaike = new SearchSite({
name: 'BaiduBaike',
icon: 'icon/baike.png',
home: 'http://baike.baidu.com/',
searchUrl: 'http://baike.baidu.com/search?word=%s&pn=0&rn=0&enc=utf8',
name: 'BaiduBaike',
icon: 'icon/baike.png',
home: 'http://baike.baidu.com/',
searchUrl: 'http://baike.baidu.com/search?word=%s&pn=0&rn=0&enc=utf8',
});
const Wiki = new SearchSite({
name: 'WikiCN',
icon: 'icon/wiki.png',
home: 'https://zh.wikipedia.org/',
searchUrl: 'https://zh.wikipedia.org/zh-cn/%s',
matches: ['//[\\w]*\\.wikipedia\\.org'],
q: 'wiki'
name: 'WikiCN',
icon: 'icon/wiki.png',
home: 'https://zh.wikipedia.org/',
searchUrl: 'https://zh.wikipedia.org/zh-cn/%s',
matches: ['//[\\w]*\\.wikipedia\\.org'],
q: 'wiki'
});
const Wikiwand = new SearchSite({
name: 'Wikiwand',
icon: 'icon/wikiwand.png',
home: 'https://www.wikiwand.com/',
searchUrl: 'https://www.wikiwand.com/zh-cn/%s',
matches: ['//[\\w]*\\.wikiwand\\.com'],
q: 'wiki'
name: 'Wikiwand',
icon: 'icon/wikiwand.png',
home: 'https://www.wikiwand.com/',
searchUrl: 'https://www.wikiwand.com/zh-cn/%s',
matches: ['//[\\w]*\\.wikiwand\\.com'],
q: 'wiki'
});
const Bilibili = new SearchSite({
name: 'Bilibili',
icon: 'icon/bilibili.png',
home: 'https://www.bilibili.com/',
searchUrl: 'https://search.bilibili.com/all?keyword=%s',
matches: ['//search\\.bilibili\\.com']
name: 'Bilibili',
icon: 'icon/bilibili.png',
home: 'https://www.bilibili.com/',
searchUrl: 'https://search.bilibili.com/all?keyword=%s',
matches: ['//search\\.bilibili\\.com']
});
const Zhihu = new SearchSite({
name: 'Zhihu',
icon: 'icon/zhihu.png',
home: 'https://www.zhihu.com/',
searchUrl: 'https://www.zhihu.com/search?q=%s',
matches: ['//[\\w]*\\.zhihu\\.com']
name: 'Zhihu',
icon: 'icon/zhihu.png',
home: 'https://www.zhihu.com/',
searchUrl: 'https://www.zhihu.com/search?q=%s',
matches: ['//[\\w]*\\.zhihu\\.com']
});
const Taobao = new SearchSite({
name: 'Taobao',
icon: 'icon/taobao.png',
home: 'https://www.taobao.com',
searchUrl: 'https://s.taobao.com/search?q=%s',
matches: ['//[\\w]*\\.taobao\\.com']
name: 'Taobao',
icon: 'icon/taobao.png',
home: 'https://www.taobao.com',
searchUrl: 'https://s.taobao.com/search?q=%s',
matches: ['//[\\w]*\\.taobao\\.com']
});
const Jingdong = new SearchSite({
name: 'Jingdong',
icon: 'icon/jd.png',
home: 'https://www.jd.com/',
searchUrl: 'https://search.jd.com/Search?keyword=%s&enc=utf-8',
matches: ['//[\\w]*\\.jd\\.com']
name: 'Jingdong',
icon: 'icon/jd.png',
home: 'https://www.jd.com/',
searchUrl: 'https://search.jd.com/Search?keyword=%s&enc=utf-8',
matches: ['//[\\w]*\\.jd\\.com']
});
const Github = new SearchSite({
name: 'Github',
icon: 'icon/github.png',
home: 'https://www.github.com/',
searchUrl: 'https://github.com/search?q=%s',
matches: ['//[\\w\\.]*github\\.com.*search']
name: 'Github',
icon: 'icon/github.png',
home: 'https://www.github.com/',
searchUrl: 'https://github.com/search?q=%s',
matches: ['//[\\w\\.]*github\\.com.*search']
});
const Douban = new SearchSite({
name: 'Douban',
icon: 'icon/douban.png',
home: 'https://www.douban.com/',
searchUrl: 'https://www.douban.com/search?q=%s',
matches: ['//[\\w]*\\.douban\\.com']
name: 'Douban',
icon: 'icon/douban.png',
home: 'https://www.douban.com/',
searchUrl: 'https://www.douban.com/search?q=%s',
matches: ['//[\\w]*\\.douban\\.com']
});
const Smzdm = new SearchSite({
name: 'Smzdm',
icon: 'icon/smzdm.png',
home: 'https://www.smzdm.com/',
searchUrl: 'https://search.smzdm.com/?s=%s',
matches: ['//[\\w]*\\.smzdm\\.com'],
q: 's'
name: 'Smzdm',
icon: 'icon/smzdm.png',
home: 'https://www.smzdm.com/',
searchUrl: 'https://search.smzdm.com/?s=%s',
matches: ['//[\\w]*\\.smzdm\\.com'],
q: 's'
});
const sysSites = [Baidu, Google, Bing, Taobao, Jingdong, Zhihu, Wiki, BaiduBaike, Bilibili, Douyin, Github, Smzdm, Douban, Youku, Wikiwand];
19 changes: 19 additions & 0 deletions js/syncloc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// migrate the content from chrome.storage.local to chrome.storage.sync
chrome.runtime.onInstalled.addListener(function (details) {
if (details.reason === 'install' || details.reason === 'update') {
chrome.storage.sync.get(null, function (syncData) {
if (Object.keys(syncData).length === 0) {
chrome.storage.local.get(null, function (localData) {
chrome.storage.sync.set(localData, function () {
if (chrome.runtime.lastError) {
console.error("Failed to migrate data to chrome.storage.sync:", chrome.runtime.lastError);
} else {
console.log("Data migrated to chrome.storage.sync successfully.");
chrome.storage.local.clear();
}
});
});
}
});
}
});
3 changes: 2 additions & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"background": {
"persistent": false,
"scripts": [
"js/syncloc.js",
"js/oop.js",
"js/url.js",
"js/kw.js",
Expand Down Expand Up @@ -34,5 +35,5 @@
"*://*/*"
],
"short_name": "__MSG_extName__",
"version": "2.5.0"
"version": "2.5.1"
}

0 comments on commit 004219d

Please sign in to comment.