谷歌Chrome浏览器同步检查,如果通过API /扩展启用? [英] Google Chrome Sync check if enabled via API/Extension?

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

问题描述

是否有可能以编程方式检查,如果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,和谷歌),但到目前为止,我还没有任何运气。

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

如果任何人有一个想法/解决方案,我最好的AP preciate的帮助。

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

干杯。

推荐答案

谷歌有一个网页,看看您的同步帐户的状态;该页面的URL是的<$c$c>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.
    }
});

祝你好运。

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

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