From ec35c788590fd1e6d7252ee65110ed41a7c5a149 Mon Sep 17 00:00:00 2001 From: yckj0834 Date: Wed, 25 Mar 2020 00:51:26 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=B0=83=E7=A0=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/gitee.js | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 js/gitee.js diff --git a/js/gitee.js b/js/gitee.js new file mode 100644 index 0000000..a8b9f0c --- /dev/null +++ b/js/gitee.js @@ -0,0 +1,9 @@ +https://gitee.com/api/v5/swagger#/getV5ReposOwnerRepoGitTreesSha 获取项目文件和递归所有文件 +https://gitee.com/api/v5/swagger#/getV5ReposOwnerRepoContents(Path) 获取文件内容 +https://gitee.com/api/v5/swagger#/postV5ReposOwnerRepoContentsPath 新建文件 +https://gitee.com/api/v5/swagger#/putV5ReposOwnerRepoContentsPath 更新文件 +https://gitee.com/api/v5/swagger#/deleteV5ReposOwnerRepoContentsPath 删除文件 +https://gitee.com/api/v5/swagger#/getV5ReposOwnerRepoBranches 获取所有分支 +https://gitee.com/api/v5/swagger#/postV5ReposOwnerRepoBranches 创建分支 +https://gitee.com/api/v5/swagger#/getV5ReposOwnerRepoCommits 仓库的所有提交(分页) +https://gitee.com/api/v5/swagger#/getV5ReposOwnerRepoCommitsSha 仓库的某个提交 \ No newline at end of file -- Gitee From d1e82be11cfcc83968f7fa4cbea50dc54deb3d5b Mon Sep 17 00:00:00 2001 From: lflxp <382023823@qq.com> Date: Wed, 25 Mar 2020 22:06:47 +0800 Subject: [PATCH 2/5] demo --- js/gitee.js | 141 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 132 insertions(+), 9 deletions(-) diff --git a/js/gitee.js b/js/gitee.js index a8b9f0c..22e9f96 100644 --- a/js/gitee.js +++ b/js/gitee.js @@ -1,9 +1,132 @@ -https://gitee.com/api/v5/swagger#/getV5ReposOwnerRepoGitTreesSha 获取项目文件和递归所有文件 -https://gitee.com/api/v5/swagger#/getV5ReposOwnerRepoContents(Path) 获取文件内容 -https://gitee.com/api/v5/swagger#/postV5ReposOwnerRepoContentsPath 新建文件 -https://gitee.com/api/v5/swagger#/putV5ReposOwnerRepoContentsPath 更新文件 -https://gitee.com/api/v5/swagger#/deleteV5ReposOwnerRepoContentsPath 删除文件 -https://gitee.com/api/v5/swagger#/getV5ReposOwnerRepoBranches 获取所有分支 -https://gitee.com/api/v5/swagger#/postV5ReposOwnerRepoBranches 创建分支 -https://gitee.com/api/v5/swagger#/getV5ReposOwnerRepoCommits 仓库的所有提交(分页) -https://gitee.com/api/v5/swagger#/getV5ReposOwnerRepoCommitsSha 仓库的某个提交 \ No newline at end of file +// https://gitee.com/api/v5/swagger#/getV5ReposOwnerRepoGitTreesSha 获取项目文件和递归所有文件 +// https://gitee.com/api/v5/swagger#/getV5ReposOwnerRepoContents(Path) 获取仓库具体路径下的内容 +// https://gitee.com/api/v5/swagger#/getV5ReposOwnerRepoContents(Path) 获取文件内容 +// https://gitee.com/api/v5/swagger#/getV5ReposOwnerRepoGitBlobsSha 获取文件Blob +// https://gitee.com/api/v5/swagger#/postV5ReposOwnerRepoContentsPath 新建文件 +// https://gitee.com/api/v5/swagger#/putV5ReposOwnerRepoContentsPath 更新文件 +// https://gitee.com/api/v5/swagger#/deleteV5ReposOwnerRepoContentsPath 删除文件 +// https://gitee.com/api/v5/swagger#/getV5ReposOwnerRepoBranches 获取所有分支 +// https://gitee.com/api/v5/swagger#/postV5ReposOwnerRepoBranches 创建分支 +// https://gitee.com/api/v5/swagger#/getV5ReposOwnerRepoCommits 仓库的所有提交(分页) +// https://gitee.com/api/v5/swagger#/getV5ReposOwnerRepoCommitsSha 仓库的某个提交 +// inside: owner repo path content message branch +const git_url = 'https://gitee.com/api' +const header = {'Content-type': 'application/json;charset=UTF-8' } +const git_key = ['access_token','owner','repo'] +class Gitee { + constructor(name,sex) { + super(name) + this.sex = sex + } + + info() { + console.log(this.name + 'is' + this.sex) + } + + get nickname() { + return 'Nickname:' + this.name.toUpperCase() + } + + set nickname(name) { + this.name = name + } + + static toStrings() { + return super.toString() + ' - Man' + } + + // 新建文件 + static create(path,content,message,branch) { + chrome.storage.local.get(git_key, function (result) { + let access_token = result.access_token + let owner = result.owner + let repo = result.repo + let url = git_url + '/v5/repos/' + owner + '/' + repo + '/contents/' + path + let data = { + 'access_token': access_token, + 'content': window.btoa(content), + 'message': message, + 'branch': branch, + } + fetch(url, { + method: 'POST', + body: JSON.stringify(data), + headers: header + }).then(res => res.json()) + .catch((error) => { + chrome.notifications.create(null, { + type: 'basic', + iconUrl: 'img/icon.png', + title: '创建 ' + path, + message: error + }) + }) + .then((resp) => { + console.log('创建' + path,resp) + }) + }) + } + + // 获取仓库具体路径下的内容和具体文件的内容 + // @param path 文件路径 + // @param ref 分支、tag或commit。默认: 仓库的默认分支(通常是master) + static getlist(path,ref) { + chrome.storage.local.get(git_key, function (result) { + let access_token = result.access_token + let owner = result.owner + let repo = result.repo + let url = git_url + '/v5/repos/' + owner + '/' + repo + '/contents/' + ref + '?access_token=' + access_token + fetch(url, { + method: 'GET', + headers: header + }).then(res => res.json()) + .catch((error) => { + chrome.notifications.create(null, { + type: 'basic', + iconUrl: 'img/icon.png', + title: '获取仓库路径 ' + path, + message: error + }) + }) + .then((resp) => { + console.log(resp) + return resp + }) + }) + } + + // 获取指定文件内容 + static get(sha) { + chrome.bookmarks.getTree((re) => { + removeall(re) + + chrome.storage.local.get(git_key, function (result) { + let access_token = result.access_token + let owner = result.owner + let repo = result.repo + let url = git_url + '/v5/repos/' + owner + '/' + repo + '/git/blobs/' + sha + '?access_token=' + access_token + fetch(url, { + method: 'GET', + headers: header + }).then(res => res.json()) + .catch((error) => { + chrome.notifications.create(null, { + type: 'basic', + iconUrl: 'img/icon.png', + title: '获取文件Blob ' + path, + message: error + }) + }) + .then((resp) => { + console.log(resp) + return window.atob(resp.content) + }) + }) + }) + } +} + +var boy = new Gitee("Li","male") +boy.info() +boy.nickname = 'Lixp' +console.log(boy.nickname) \ No newline at end of file -- Gitee From 9480f01239c5b8b306b5b2e9b13ad9ab0d347495 Mon Sep 17 00:00:00 2001 From: lflxp <382023823@qq.com> Date: Thu, 26 Mar 2020 19:15:09 +0800 Subject: [PATCH 3/5] api almost finish --- js/gitee.js | 174 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 169 insertions(+), 5 deletions(-) diff --git a/js/gitee.js b/js/gitee.js index 22e9f96..1551e3c 100644 --- a/js/gitee.js +++ b/js/gitee.js @@ -35,7 +35,13 @@ class Gitee { return super.toString() + ' - Man' } - // 新建文件 + /** + * API文档 https://gitee.com/api/v5/swagger#/postV5ReposOwnerRepoContentsPath 新建文件 + * @param {*} path + * @param {*} content + * @param {*} message + * @param {*} branch + */ static create(path,content,message,branch) { chrome.storage.local.get(git_key, function (result) { let access_token = result.access_token @@ -67,9 +73,11 @@ class Gitee { }) } - // 获取仓库具体路径下的内容和具体文件的内容 - // @param path 文件路径 - // @param ref 分支、tag或commit。默认: 仓库的默认分支(通常是master) + /** + * API文档:https://gitee.com/api/v5/swagger#/getV5ReposOwnerRepoContents(Path) 获取仓库具体路径下的内容 + * @param {*} path 文件路径 + * @param {*} ref 分支、tag或commit。默认: 仓库的默认分支(通常是master) + */ static getlist(path,ref) { chrome.storage.local.get(git_key, function (result) { let access_token = result.access_token @@ -96,6 +104,10 @@ class Gitee { } // 获取指定文件内容 + /** + * API文档:https://gitee.com/api/v5/swagger#/getV5ReposOwnerRepoGitBlobsSha 获取文件Blob + * @param {*} sha + */ static get(sha) { chrome.bookmarks.getTree((re) => { removeall(re) @@ -119,11 +131,163 @@ class Gitee { }) .then((resp) => { console.log(resp) - return window.atob(resp.content) + let info = JSON.parse(decodeURIComponent(window.atob(result['content']))) + try { + addAll(info[0].children,'') + } catch (e) { + console.log('error',e) + } finally { + chrome.notifications.create(null, { + type: 'basic', + iconUrl: 'img/icon.png', + title: '更新本地书签', + message: '同步完成 ' + }) + } + // return window.atob(resp.content) }) }) }) } + + /** + * API文档: https://gitee.com/api/v5/swagger#/putV5ReposOwnerRepoContentsPath 更新文件 + * @param {*} path + * @param {*} content + * @param {*} message + */ + static updateTags(path,content,message) { + chrome.storage.local.get(git_key, function (result) { + let _this = this + let access_token = result.access_token + let owner = result.owner + let repo = result.repo + + let url = git_url + '/v5/repos/' + owner + '/' + repo + '/contents/' + ref + '?access_token=' + access_token + fetch(url, { + method: 'GET', + headers: header + }).then(res => res.json()) + .catch((error) => { + chrome.notifications.create(null, { + type: 'basic', + iconUrl: 'img/icon.png', + title: '获取仓库路径 ' + path, + message: error + }) + }) + .then((resp) => { + let data = { + "access_token": access_token, + "content": window.btoa(content), + "sha": resp['sha'], + "message": message + } + + let put_url = git_url + '/v5/repos/' + owner + '/' + repo + '/contents/' + path + fetch(put_url, { + method: 'PUT', + body: JSON.stringify(data), + headers: header + }).then(res => res.json()) + .catch((error) => { + chrome.notifications.create(null, { + type: 'basic', + iconUrl: 'img/icon.png', + title: '上传全量书签错误', + message: error + }) + }) + .then((resp) => { + console.log(resp) + chrome.notifications.create(null, { + type: 'basic', + iconUrl: 'img/icon.png', + title: '上传全量书签', + message: '成功' + }) + }) + }) + }) + } + + /** + * API文档:https://gitee.com/api/v5/swagger#/deleteV5ReposOwnerRepoContentsPath 删除文件 + * @param {*} path + * @param {*} message + */ + static delete(path,message) { + chrome.storage.local.get(git_key, function (result) { + let _this = this + let access_token = result.access_token + let owner = result.owner + let repo = result.repo + + let url = git_url + '/v5/repos/' + owner + '/' + repo + '/contents/' + ref + '?access_token=' + access_token + fetch(url, { + method: 'GET', + headers: header + }).then(res => res.json()) + .catch((error) => { + chrome.notifications.create(null, { + type: 'basic', + iconUrl: 'img/icon.png', + title: '获取仓库路径 ' + path, + message: error + }) + }) + .then((resp) => { + let del_url = git_url + '/v5/repos/' + owner + '/' + repo + '/contents/' + path + '?access_token=' + access_token + '&sha=' + resp['sha'] + '&message=' + message + fetch(del_url, { + method: 'DELETE', + headers: header + }).then(res => res.json()) + .catch((error) => { + console.error('Error:', error) + }) + .then((resp) => { + console.log('github delete success' + JSON.stringify(resp)) + chrome.notifications.create(null, { + type: 'basic', + iconUrl: 'img/icon.png', + title: '书签删除', + message: '远程书签 ' + filepath + ' 删除完毕!' + }) + }) + }) + }) + } + + /** + * API文档:https://gitee.com/api/v5/swagger#/getV5ReposOwnerRepoCommits 仓库的所有提交(分页) + * @param {*} path 包含该文件的提交 + * @param {*} page 当前的页码 + * @param {*} per_page 每页的数量,最大为 100 + */ + static getallcommit(path,page,per_page) { + chrome.storage.local.get(git_key, function (result) { + let access_token = result.access_token + let owner = result.owner + let repo = result.repo + let url = git_url + '/v5/repos/' + owner + '/' + repo + '/commits?access_token=' + access_token + '&path=' + path + '&page=' + page + '&per_page=' + per_page + fetch(url, { + method: 'GET', + headers: header + }).then(res => res.json()) + .catch((error) => { + chrome.notifications.create(null, { + type: 'basic', + iconUrl: 'img/icon.png', + title: '仓库的所有提交 ' + path, + message: error + }) + }) + .then((resp) => { + console.log(resp) + return resp + }) + }) + } } var boy = new Gitee("Li","male") -- Gitee From 717aa3aa4bb2613d7d63973aa44578924ab115b1 Mon Sep 17 00:00:00 2001 From: yckj0834 Date: Thu, 26 Mar 2020 23:08:11 +0800 Subject: [PATCH 4/5] init --- js/gitee.js | 40 +++++++--------------------------------- js/popup.js | 18 +++++++++++++++--- manifest.json | 2 +- 3 files changed, 23 insertions(+), 37 deletions(-) diff --git a/js/gitee.js b/js/gitee.js index 1551e3c..c0bb5bb 100644 --- a/js/gitee.js +++ b/js/gitee.js @@ -13,28 +13,7 @@ const git_url = 'https://gitee.com/api' const header = {'Content-type': 'application/json;charset=UTF-8' } const git_key = ['access_token','owner','repo'] -class Gitee { - constructor(name,sex) { - super(name) - this.sex = sex - } - - info() { - console.log(this.name + 'is' + this.sex) - } - - get nickname() { - return 'Nickname:' + this.name.toUpperCase() - } - - set nickname(name) { - this.name = name - } - - static toStrings() { - return super.toString() + ' - Man' - } - +function Gitee() { /** * API文档 https://gitee.com/api/v5/swagger#/postV5ReposOwnerRepoContentsPath 新建文件 * @param {*} path @@ -42,7 +21,7 @@ class Gitee { * @param {*} message * @param {*} branch */ - static create(path,content,message,branch) { + this.create = function (path,content,message,branch) { chrome.storage.local.get(git_key, function (result) { let access_token = result.access_token let owner = result.owner @@ -78,7 +57,7 @@ class Gitee { * @param {*} path 文件路径 * @param {*} ref 分支、tag或commit。默认: 仓库的默认分支(通常是master) */ - static getlist(path,ref) { + this.getlist = function (path,ref) { chrome.storage.local.get(git_key, function (result) { let access_token = result.access_token let owner = result.owner @@ -108,7 +87,7 @@ class Gitee { * API文档:https://gitee.com/api/v5/swagger#/getV5ReposOwnerRepoGitBlobsSha 获取文件Blob * @param {*} sha */ - static get(sha) { + this.get = function (sha) { chrome.bookmarks.getTree((re) => { removeall(re) @@ -156,7 +135,7 @@ class Gitee { * @param {*} content * @param {*} message */ - static updateTags(path,content,message) { + this.updateTags = function (path,content,message) { chrome.storage.local.get(git_key, function (result) { let _this = this let access_token = result.access_token @@ -216,7 +195,7 @@ class Gitee { * @param {*} path * @param {*} message */ - static delete(path,message) { + this.delete = function (path,message) { chrome.storage.local.get(git_key, function (result) { let _this = this let access_token = result.access_token @@ -264,7 +243,7 @@ class Gitee { * @param {*} page 当前的页码 * @param {*} per_page 每页的数量,最大为 100 */ - static getallcommit(path,page,per_page) { + this.getallcommit = function (path,page,per_page) { chrome.storage.local.get(git_key, function (result) { let access_token = result.access_token let owner = result.owner @@ -289,8 +268,3 @@ class Gitee { }) } } - -var boy = new Gitee("Li","male") -boy.info() -boy.nickname = 'Lixp' -console.log(boy.nickname) \ No newline at end of file diff --git a/js/popup.js b/js/popup.js index b165f67..e1a887b 100644 --- a/js/popup.js +++ b/js/popup.js @@ -23,10 +23,22 @@ document.getElementById('commit').onclick = function () { let repos = tmp[tmp.length - 1] let token = document.getElementById('token').value - chrome.storage.local.set({ 'username': username, 'repos': repos, 'token': token }, () => { + // chrome.storage.local.set({ 'username': username, 'repos': repos, 'token': token }, () => { + // let bg = chrome.extension.getBackgroundPage() + // let github = new bg.Github() + // github.create('bookmarks/create') + // chrome.notifications.create(null, { + // type: 'basic', + // iconUrl: 'img/icon.png', + // title: '保存配置', + // message: '认证配置成功' + // }) + // }) + + chrome.storage.local.set({ 'owner': username, 'repo': repos, 'access_token': token }, () => { let bg = chrome.extension.getBackgroundPage() - let github = new bg.Github() - github.create('bookmarks/create') + let github = new bg.Gitee() + github.create('apitest/bookmarks','init','init','master') chrome.notifications.create(null, { type: 'basic', iconUrl: 'img/icon.png', diff --git a/manifest.json b/manifest.json index a8ada0e..4303b48 100644 --- a/manifest.json +++ b/manifest.json @@ -22,7 +22,7 @@ "default_popup": "popup.html" }, "background": { - "scripts": ["js/background.js","js/github.js","js/bookmark.js"] + "scripts": ["js/background.js","js/github.js","js/bookmark.js","js/gitee.js"] }, "omnibox": {"keyword": "go"}, "homepage_url": "https://gitee.com/CLCoding/chrome-bookmark" -- Gitee From e5fe9be50b50d3af82dff250024da1ce41f41f13 Mon Sep 17 00:00:00 2001 From: yckj0834 Date: Fri, 27 Mar 2020 00:48:30 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E5=8A=9F=E8=83=BD=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/gitee.js | 122 +++++++++++++++++++++++++++++++++++++++++----------- js/popup.js | 61 +++++++++++++++++++------- popup.html | 2 + 3 files changed, 144 insertions(+), 41 deletions(-) diff --git a/js/gitee.js b/js/gitee.js index c0bb5bb..86a8c12 100644 --- a/js/gitee.js +++ b/js/gitee.js @@ -12,7 +12,8 @@ // inside: owner repo path content message branch const git_url = 'https://gitee.com/api' const header = {'Content-type': 'application/json;charset=UTF-8' } -const git_key = ['access_token','owner','repo'] +const git_key = ['access_token','owner','repo','version'] +const initext = 'ZGQK' function Gitee() { /** * API文档 https://gitee.com/api/v5/swagger#/postV5ReposOwnerRepoContentsPath 新建文件 @@ -57,12 +58,13 @@ function Gitee() { * @param {*} path 文件路径 * @param {*} ref 分支、tag或commit。默认: 仓库的默认分支(通常是master) */ - this.getlist = function (path,ref) { + this.getlist = function (path,ref,element,elenum) { chrome.storage.local.get(git_key, function (result) { let access_token = result.access_token let owner = result.owner let repo = result.repo - let url = git_url + '/v5/repos/' + owner + '/' + repo + '/contents/' + ref + '?access_token=' + access_token + let version = result.version + let url = git_url + '/v5/repos/' + owner + '/' + repo + '/contents/' + path + '?access_token=' + access_token + '&ref=' + ref fetch(url, { method: 'GET', headers: header @@ -77,7 +79,14 @@ function Gitee() { }) .then((resp) => { console.log(resp) - return resp + resp.forEach((vds) => { + var op = document.createElement('option'); + op.setAttribute('label', vds['name']); + op.setAttribute('value', vds['name']); + op.setAttribute('select', 'select') + element.appendChild(op); + }) + elenum.innerText = resp.length }) }) } @@ -131,35 +140,20 @@ function Gitee() { /** * API文档: https://gitee.com/api/v5/swagger#/putV5ReposOwnerRepoContentsPath 更新文件 - * @param {*} path - * @param {*} content + * @param {*} sha * @param {*} message */ - this.updateTags = function (path,content,message) { + this.updateTagsSha = function (sha,message) { chrome.storage.local.get(git_key, function (result) { - let _this = this let access_token = result.access_token let owner = result.owner let repo = result.repo - let url = git_url + '/v5/repos/' + owner + '/' + repo + '/contents/' + ref + '?access_token=' + access_token - fetch(url, { - method: 'GET', - headers: header - }).then(res => res.json()) - .catch((error) => { - chrome.notifications.create(null, { - type: 'basic', - iconUrl: 'img/icon.png', - title: '获取仓库路径 ' + path, - message: error - }) - }) - .then((resp) => { + chrome.bookmarks.getTree((re) => { let data = { "access_token": access_token, - "content": window.btoa(content), - "sha": resp['sha'], + "content": window.btoa(encodeURIComponent(JSON.stringify(re))), + "sha": sha, "message": message } @@ -190,6 +184,75 @@ function Gitee() { }) } + /** + * API文档: https://gitee.com/api/v5/swagger#/putV5ReposOwnerRepoContentsPath 更新文件 + * @param {*} path + * @param {*} message + * @param {*} ref + */ + this.updateTags = function (path,message,ref) { + let _this = this + chrome.storage.local.get(git_key, function (result) { + let access_token = result.access_token + let owner = result.owner + let repo = result.repo + + // https://gitee.com/api/v5/swagger#/getV5ReposOwnerRepoContents(Path) 获取仓库具体路径下的内容 + let url = git_url + '/v5/repos/' + owner + '/' + repo + '/contents/' + path + '?access_token=' + access_token + '&ref=' + ref + fetch(url, { + method: 'GET', + headers: header + }).then(res => res.json()) + .catch((error) => { + chrome.notifications.create(null, { + type: 'basic', + iconUrl: 'img/icon.png', + title: '获取仓库路径 ' + path, + message: error + }) + }) + .then((resp) => { + console.log('gitee get success' + JSON.stringify(resp), resp['sha']) + if (resp['sha'] == undefined) { + _this.create(path,initext,'init','master') + _this.updateTags(path,message,ref) + } + chrome.bookmarks.getTree((re) => { + let data = { + "access_token": access_token, + "content": window.btoa(encodeURIComponent(JSON.stringify(re))), + "sha": resp['sha'], + "message": message + } + + let put_url = git_url + '/v5/repos/' + owner + '/' + repo + '/contents/' + path + fetch(put_url, { + method: 'PUT', + body: JSON.stringify(data), + headers: header + }).then(res => res.json()) + .catch((error) => { + chrome.notifications.create(null, { + type: 'basic', + iconUrl: 'img/icon.png', + title: '上传全量书签错误', + message: error + }) + }) + .then((resp) => { + console.log(resp) + chrome.notifications.create(null, { + type: 'basic', + iconUrl: 'img/icon.png', + title: '上传全量书签', + message: '成功' + }) + }) + }) + }) + }) + } + /** * API文档:https://gitee.com/api/v5/swagger#/deleteV5ReposOwnerRepoContentsPath 删除文件 * @param {*} path @@ -262,8 +325,15 @@ function Gitee() { }) }) .then((resp) => { - console.log(resp) - return resp + // console.log(resp) + // return resp + resp.forEach((vds) => { + var op = document.createElement('option'); + op.setAttribute('label', vds['commit']['message']); + op.setAttribute('value', vds['commit']['message']); + op.setAttribute('select', 'select') + element.appendChild(op); + }) }) }) } diff --git a/js/popup.js b/js/popup.js index e1a887b..cb4297b 100644 --- a/js/popup.js +++ b/js/popup.js @@ -25,7 +25,7 @@ document.getElementById('commit').onclick = function () { // chrome.storage.local.set({ 'username': username, 'repos': repos, 'token': token }, () => { // let bg = chrome.extension.getBackgroundPage() - // let github = new bg.Github() + // let github = new bg.Gitee() // github.create('bookmarks/create') // chrome.notifications.create(null, { // type: 'basic', @@ -35,10 +35,10 @@ document.getElementById('commit').onclick = function () { // }) // }) - chrome.storage.local.set({ 'owner': username, 'repo': repos, 'access_token': token }, () => { + chrome.storage.local.set({ 'owner': username, 'repo': repos, 'access_token': token,'version': 'init' }, () => { let bg = chrome.extension.getBackgroundPage() let github = new bg.Gitee() - github.create('apitest/bookmarks','init','init','master') + github.create('bookmarks/init','init','init','master') chrome.notifications.create(null, { type: 'basic', iconUrl: 'img/icon.png', @@ -59,7 +59,7 @@ document.getElementById('clearonline').onclick = function () { let files = document.getElementById('filename').value if (files !== '' && files !== undefined) { let bg = chrome.extension.getBackgroundPage() - let github = new bg.Github() + let github = new bg.Gitee() github.delete('bookmarks/' + files, '删除' + files) $('#message-success').innerText = '远程删除成功' @@ -75,8 +75,12 @@ document.getElementById('upload').onclick = function () { let files = document.getElementById('filename').value if (files !== '' && files !== undefined) { let bg = chrome.extension.getBackgroundPage() - let github = new bg.Github() - github.updateTags('bookmarks/' + files, getDate()) + let github = new bg.Gitee() + github.updateTags('bookmarks/' + files, getDate(),'master') + + chrome.storage.local.set({ 'version': files }, () => { + $('#version-repo').value = files + }) $('#message-success').innerText = '同步上传成功' clearAndFadeMessage($('#message-success')) @@ -86,13 +90,37 @@ document.getElementById('upload').onclick = function () { } } +// 查看全量commit +document.getElementById('commit').onclick = function () { + let files = document.getElementById('filename').value + if (files !== '' && files !== undefined) { + let bg = chrome.extension.getBackgroundPage() + let github = new bg.Gitee() + github.getallcommit(files,1,10) + + chrome.storage.local.set({ 'version': files }, () => { + $('#version-repo').value = version + }) + + $('#message-success').innerText = '获取全量commit成功' + clearAndFadeMessage($('#message-success')) + } else { + $('#message-error').innerText = '未选定文件名' + clearAndFadeMessage($('#message-error')) + } +} + // 全量同步下载 document.getElementById('download').onclick = function () { let files = document.getElementById('filename').value if (files !== '' && files !== undefined) { let bg = chrome.extension.getBackgroundPage() - let github = new bg.Github() - github.get('bookmarks/' + files) + let github = new bg.Gitee() + github.get(files) + + chrome.storage.local.set({ 'version': files }, () => { + $('#version-repo').value = version + }) $('#message-success').innerText = '更新下载成功' clearAndFadeMessage($('#message-success')) @@ -143,18 +171,20 @@ function clearAndFadeMessage(element, time = 3000) { } window.onload = function () { - let key = ['username', 'repos', 'token', 'localnum'] + let key = ['owner', 'repo', 'access_token', 'localnum','version'] let username; let repos; let token; let localnum; + let version; let bg = chrome.extension.getBackgroundPage(); chrome.storage.local.get(key, function (result) { - username = result.username; - repos = result.repos; - token = result.token; + username = result.owner; + repos = result.repo; + token = result.access_token; localnum = result.localnum; + version = result.version if (localnum === '' || localnum === undefined) { bg.countBookmarks($('#count-local')) @@ -164,14 +194,15 @@ window.onload = function () { $('#message-error').innerText = '未配置认证信息' clearAndFadeMessage($('#message-error')) } else { - $('#repos').value = 'https://github.com/' + username + '/' + repos + $('#repos').value = 'https://gitee.com/' + username + '/' + repos $('#token').value = token + $('#version-repo').value = version switch2Main() } }) // 获取目录 - let github = new bg.Github(); - github.getlist('bookmarks/', $('#greetings'), $('#count-repo')); + let github = new bg.Gitee(); + github.getlist('bookmarks/','master', $('#greetings'), $('#count-repo')); } \ No newline at end of file diff --git a/popup.html b/popup.html index 4ffc12b..364d6dd 100644 --- a/popup.html +++ b/popup.html @@ -24,6 +24,7 @@
本地有--条书签
线上有--个备份版本
+
当前远程版本--
@@ -34,6 +35,7 @@
+
-- Gitee