Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3250)

Unified Diff: chrome/common/extensions/docs/examples/api/idle/idle_simple/history.html

Issue 9289057: Changing manifest to v2 extension samples (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Adding zip files after rebasing with master Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/docs/examples/api/idle/idle_simple/history.html
diff --git a/chrome/common/extensions/docs/examples/api/idle/idle_simple/history.html b/chrome/common/extensions/docs/examples/api/idle/idle_simple/history.html
index 34b141487186bb86bc780469390176c7ad402f2c..c8061c5601ea4ac65318b876b3d69103dd0edac3 100644
--- a/chrome/common/extensions/docs/examples/api/idle/idle_simple/history.html
+++ b/chrome/common/extensions/docs/examples/api/idle/idle_simple/history.html
@@ -12,31 +12,7 @@
font: 13px Arial;
}
</style>
- <script>
- /**
- * Convert a state and time into a nice styled chunk of HTML.
- */
- function renderState(state, time) {
- var now = new Date().getTime();
- var diff = Math.round((time.getTime() - now) / 1000);
- var str = (diff == 0) ?
- "now" :
- Math.abs(diff) + " seconds " + (diff > 0 ? "from now" : "ago");
- var col = (state == "active") ?
- "#009900" :
- "#990000";
- return "<b style='color: " + col + "'>" + state + "</b> " + str;
- };
-
- /**
- * Creates DOM and injects a rendered state into the page.
- */
- function renderItem(state, time, parent) {
- var dom_item = document.createElement('li');
- dom_item.innerHTML = renderState(state, time);
- parent.appendChild(dom_item);
- };
- </script>
+ <script src="history.js"></script>
</head>
<body>
<h1>Idle API Demonstration</h1>
@@ -55,64 +31,8 @@
<p>
Last state change: <span id="idle-laststate"></span>
</p>
- <script>
- // Store previous state so we can show deltas. This is important
- // because the API currently doesn't fire idle messages, and we'd
- // like to keep track of last time we went idle.
- var laststate = null;
- var laststatetime = null;
-
- /**
- * Checks the current state of the browser.
- */
- function checkState() {
- threshold = parseInt(document.querySelector('#idle-threshold').value);
- var dom_threshold = document.querySelector('#idle-set-threshold');
- dom_threshold.innerText = threshold;
-
- // Request the state based off of the user-supplied threshold.
- chrome.idle.queryState(threshold, function(state) {
- var time = new Date();
- if (laststate != state) {
- laststate = state;
- laststatetime = time;
- }
-
- // Keep rendering results so we get a nice "seconds elapsed" view.
- var dom_result = document.querySelector('#idle-state');
- dom_result.innerHTML = renderState(state, time);
- var dom_laststate = document.querySelector('#idle-laststate');
- dom_laststate.innerHTML = renderState(laststate, laststatetime);
- });
- };
-
- // Check every second (even though this is overkill - minimum idle
- // threshold is 15 seconds) so that the numbers appear to be counting up.
- checkState();
- window.setInterval(checkState, 1000);
- </script>
<h2>Idle changes:</h2>
<ul id='idle-history'></ul>
- <script>
- var dom_history = document.querySelector('#idle-history');
-
- /**
- * Render the data gathered by the background page - should show a log
- * of "active" states. No events are fired upon idle.
- */
- function renderHistory() {
- dom_history.innerHTML = "";
- var history_log = chrome.extension.getBackgroundPage().history_log;
- for (var i = 0; i < history_log.length; i++) {
- var data = history_log[i];
- renderItem(data['state'], data['time'], dom_history);
- }
- };
-
- // Check every second (see above).
- renderHistory();
- window.setInterval(renderHistory, 1000);
- </script>
</body>
</html>

Powered by Google App Engine
This is Rietveld 408576698