Google Chrome 同步检查是否通过 API/扩展启用? [英] Google Chrome Sync check if enabled via API/Extension?

查看:34
本文介绍了Google Chrome 同步检查是否通过 API/扩展启用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过编程方式检查 Google Chrome 中是否配置了 Chrome 同步?

Is it possible to programmatically check if Chrome Sync is configured in Google Chrome?

我问的原因是我正在编写一个依赖于 Chrome 同步的 Chrome 扩展程序,如果它没有配置,我想检查/通知用户.

The reason I ask is that I am coding an Extension for Chrome that depends on Chrome Sync, and would like to check/inform the user if it's not configured.

在发布这个问题之前,我检查了明显的地方(Chrome 扩展 API、StackExchange 和 Google),但到目前为止我还没有任何运气.

Before posting this question I checked the obvious places (Chrome Extension APIs, StackExchange, and Google), but so far I haven't had any luck.

如果有人有想法/解决方案,我将不胜感激.

If anyone has an idea/solution I'd appreciate the help.

干杯.

推荐答案

Google 有一个页面可以查看您已同步帐户的状态;该页面的 URL 是 https://www.google.com/settings/chrome/sync.您可以使用谷歌允许扩展的跨域连接来查看帐户是否同步打开该状态页面(如果它甚至没有返回 200-OK 状态未同步),然后您使用一点 JavaScript从该页面提取上次同步"日期;之后只需使用 chrome.storage.sync API 保存它,然后几秒钟后再次检查上次同步"日期,如果它改变了,那么你可以 99% 确定已同步(或者如果你想覆盖同步缓慢的情况,只需使用 setInterval 等待它).

Google has a page to see the status of your synced account; the URL of that page is https://www.google.com/settings/chrome/sync. Something you can do to see if an account is synced is opening that status page using cross-domain connections that Google allows for extensions (if it doesn't even return 200-OK status is not synced) and then you use a little JavaScript to extract the "Last Sync" date from that page; after that just save it using the chrome.storage.sync API and then a few seconds later check again the "Last Sync" date, if it changed then you can be 99% sure is synced (or if you want to cover the case of slow synchronizations just use setInterval to wait for it).

您可以使用以下 JavaScript 来提取日期:

You can use the following JavaScript to extract the date:

NodeList.prototype.forEach = Array.prototype.forEach;
var date = null;
document.querySelectorAll("*").forEach(function(ele){
    var matches = ele.innerText.match(/\b\d{4}\s\d{2}:\d{2}:\d{2}\b.*/);
    if (matches) date = matches[0];
});

第一次保存该值

chrome.storage.sync.set({date: date});

第二次你应该比较两个值,添加如下内容:

And the second time you should compare both values adding something like this:

chrome.storage.sync.get("date", function (old) {
    if (date !== old) {
        // Is sync!
    } else {
        // not sync.
    }
});

祝你好运.

这篇关于Google Chrome 同步检查是否通过 API/扩展启用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆