Skip to content

Commit 6aa5329

Browse files
committed
added the tab sepecific code in extension
1 parent b3c784a commit 6aa5329

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

extension/writing-process/src/background.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var RAW_DEBUG = false;
1212
var WEBSOCKET_SERVER_URL = "wss://learning-observer.org/wsapi/in/";
1313

1414
import { googledocs_id_from_url } from './writing_common';
15-
15+
import { tab_id_from_url } from './writing_common';
1616
import * as loEvent from 'lo_event/lo_event/lo_event.js';
1717
import * as loEventDebug from 'lo_event/lo_event/debugLog.js';
1818
import { websocketLogger } from 'lo_event/lo_event/websocketLogger.js';
@@ -210,6 +210,7 @@ chrome.webRequest.onBeforeRequest.addListener(
210210
versus GMT. */
211211
event = {
212212
'doc_id': googledocs_id_from_url(request.url),
213+
'tab_id': tab_id_from_url(request.url),
213214
'url': request.url,
214215
'bundles': JSON.parse(formdata.bundles),
215216
'rev': formdata.rev,
@@ -223,6 +224,7 @@ chrome.webRequest.onBeforeRequest.addListener(
223224
*/
224225
event = {
225226
'doc_id': googledocs_id_from_url(request.url),
227+
'tab_id': tab_id_from_url(request.url),
226228
'url': request.url,
227229
'formdata': formdata,
228230
'rev': formdata.rev,

extension/writing-process/src/writing_common.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,21 @@ export function googledocs_id_from_url(url) {
7878
return null;
7979
}
8080

81+
export function tab_id_from_url(url) {
82+
/*
83+
Given a URL like:
84+
https://docs.google.com/document/d/<doc_id>/edit?tab=t.95yb7msfl8ul
85+
extract the associated tab ID:
86+
t.95yb7msfl8ul
87+
Return null if not a valid URL or tab param.
88+
*/
89+
var match = url.match(/[?&]tab=([^&]+)/i);
90+
if (match) {
91+
return match[1];
92+
}
93+
return null;
94+
}
95+
8196
var writing_lasthash = "";
8297
function unique_id() {
8398
/*

0 commit comments

Comments
 (0)