diff --git a/window-manipulator/README.md b/window-manipulator/README.md new file mode 100644 index 0000000..46d37cf --- /dev/null +++ b/window-manipulator/README.md @@ -0,0 +1,11 @@ +# Window manipulator + +## What it does + +This extension includes a browser action with a popup specified as "window.html". + +The popup lets the user perform various simple operations using the windows API. + +# What it shows + +Demonstration of various windows API functions. diff --git a/window-manipulator/icons/window.png b/window-manipulator/icons/window.png new file mode 100644 index 0000000..e707a11 Binary files /dev/null and b/window-manipulator/icons/window.png differ diff --git a/window-manipulator/icons/window19.png b/window-manipulator/icons/window19.png new file mode 100644 index 0000000..8207534 Binary files /dev/null and b/window-manipulator/icons/window19.png differ diff --git a/window-manipulator/icons/window38.png b/window-manipulator/icons/window38.png new file mode 100644 index 0000000..b42ab1e Binary files /dev/null and b/window-manipulator/icons/window38.png differ diff --git a/window-manipulator/icons/window@2x.png b/window-manipulator/icons/window@2x.png new file mode 100644 index 0000000..9a5044e Binary files /dev/null and b/window-manipulator/icons/window@2x.png differ diff --git a/window-manipulator/manifest.json b/window-manipulator/manifest.json new file mode 100644 index 0000000..5963b9b --- /dev/null +++ b/window-manipulator/manifest.json @@ -0,0 +1,20 @@ +{ + "browser_action": { + "browser_style": true, + "default_title": "Window manipulator", + "default_popup": "window.html", + "default_icon": { + "19": "icons/window19.png", + "38": "icons/window38.png" + } + }, + "icons": { + "48": "icons/window.png", + "96": "icons/window@2x.png" + }, + "description": "A list of methods you can perform on a window.", + "homepage_url": "https://github.com/mdn/webextensions-examples/tree/master/window-manipulator", + "manifest_version": 2, + "name": "Window manipulator", + "version": "1.0" +} diff --git a/window-manipulator/window.css b/window-manipulator/window.css new file mode 100644 index 0000000..959491f --- /dev/null +++ b/window-manipulator/window.css @@ -0,0 +1,12 @@ +html, body { + width: 350px; +} + +a { + margin: 10px; + display: inline-block; +} + +.panel { + margin: 5px; +} diff --git a/window-manipulator/window.html b/window-manipulator/window.html new file mode 100644 index 0000000..8faa3ad --- /dev/null +++ b/window-manipulator/window.html @@ -0,0 +1,31 @@ + + + + + + + + + +
+
+
Window manipulator
+
+ + Resize window to 768x1024
+ Minimize
+ +
+ + Create new incognito window
+ Remove active window
+ +
+ + Resize all windows to 1024x768
+
+ + + + + diff --git a/window-manipulator/window.js b/window-manipulator/window.js new file mode 100644 index 0000000..07437b2 --- /dev/null +++ b/window-manipulator/window.js @@ -0,0 +1,58 @@ +document.addEventListener("click", (e) => { + + function callOnCurrentWindow(callback){ + chrome.windows.getCurrent((currentWindow) => { + callback(currentWindow); + }); + } + + if (e.target.id === "window-update-size_768") { + callOnCurrentWindow((currentWindow) => { + var updateInfo = { + width: 768, + height: 1024 + }; + + chrome.windows.update(currentWindow.id, updateInfo); + }); + } + + if (e.target.id === "window-update-minimize") { + callOnCurrentWindow((currentWindow) => { + var updateInfo = { + state: "minimized" + }; + + chrome.windows.update(currentWindow.id, updateInfo); + }); + } + + else if (e.target.id === "window-create-incognito") { + var createData = { + incognito: true, + }; + chrome.windows.create(createData, () => { + console.log("The incognito window has been created"); + }); + } + + else if (e.target.id === "window-remove") { + callOnCurrentWindow((currentWindow) => { + chrome.windows.remove(currentWindow.id); + }); + } + + else if (e.target.id === "window-resize-all") { + chrome.windows.getAll((windows) => { + var updateInfo = { + width: 1024, + height: 768 + }; + for (var item of windows) { + chrome.windows.update(item.id, updateInfo); + } + }); + } + + e.preventDefault(); +});