Skip to content

Commit

Permalink
Merge pull request #3 from jose01carrillo30/0.2
Browse files Browse the repository at this point in the history
0.2
  • Loading branch information
jose01carrillo30 committed Dec 29, 2023
2 parents ab8c876 + a3d2ba1 commit 54f948b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 30 deletions.
4 changes: 3 additions & 1 deletion .gitignore
@@ -1,2 +1,4 @@
*.zip
*.crx
*.crx

.vscode/
30 changes: 12 additions & 18 deletions background.js
@@ -1,30 +1,25 @@
'use strict';

chrome.runtime.onInstalled.addListener(function() {
chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
chrome.declarativeContent.onPageChanged.addRules([{
conditions: [new chrome.declarativeContent.PageStateMatcher({
pageUrl: {hostEquals: 'calendar.google.com'},
})],
actions: [new chrome.declarativeContent.ShowPageAction()]
}]);
});
});

// Listener for increment key command
chrome.commands.onCommand.addListener(function(command) {
if (command == "down-week" || command == "up-week") {
if (command == "02-down-week" || command == "01-up-week") {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
var bkg = chrome.extension.getBackgroundPage();

var tabUrl = tabs[0].url;

// check to make sure we are on a calendar
// check we are on Google Calendar
var hostname = (new URL(tabUrl)).hostname;
if (hostname != "calendar.google.com") {
return;
}

// check to make sure we are viewing the calendar
if (tabUrl.includes("trash") ||
tabUrl.includes("settings") ||
tabUrl.includes("eventedit")) {
return;
}

// ----------- get the currently selected date 'currDate' ----------- //
var urlPieces = tabUrl.split("/");
var urlDate = [];
Expand All @@ -51,13 +46,12 @@ chrome.commands.onCommand.addListener(function(command) {
var matchedRoot = tabUrl.match(/.*\/r/)[0];

// ----------- Update URL ----------- //
// increment date one week
if (command == "down-week") {
// increment date
if (command == "02-down-week") {
currDate.setDate(currDate.getDate() + 7);
} else {
currDate.setDate(currDate.getDate() - 7);
}

// set target URL with updated date
tabUrl = matchedRoot + "/customweek/"
+ currDate.getFullYear() + "/" + (currDate.getMonth() + 1) + "/" + currDate.getDate();
Expand Down
21 changes: 10 additions & 11 deletions manifest.json
@@ -1,11 +1,10 @@
{
"name": "Week Increment Google Calendar Custom View",
"version": "0.1",
"version": "0.2",
"description": "Adds shortcuts to increment the custom week view for Google Calendar one week at a time.",
"permissions": ["activeTab", "declarativeContent"],
"permissions": ["activeTab"],
"background": {
"scripts": ["background.js"],
"persistent": false
"service_worker": "background.js"
},
"icons": {
"16": "images/logo16.png",
Expand All @@ -14,14 +13,14 @@
"128": "images/logo128.png"
},
"commands": {
"down-week": {
"suggested_key": { "default": "Ctrl+Down" },
"description": "Move custom-view forward one week"
},
"up-week": {
"01-up-week": {
"suggested_key": { "default": "Ctrl+Up" },
"description": "Move custom-view backward one week"
"description": "Go backward one week in X-weeks custom view"
},
"02-down-week": {
"suggested_key": { "default": "Ctrl+Down" },
"description": "Go forward one week in X-weeks custom view"
}
},
"manifest_version": 2
"manifest_version": 3
}

0 comments on commit 54f948b

Please sign in to comment.