├── src ├── icons │ ├── icon-128.png │ ├── icon-16.png │ ├── icon-32.png │ ├── icon-48.png │ ├── icon-64.png │ ├── icon-96.png │ └── icon.svg ├── popup │ ├── popup.html │ ├── quotes.json │ ├── popup.css │ └── popup.js ├── manifest.json ├── background.js └── options │ ├── options.html │ ├── options.js │ └── options.css ├── static ├── github_preview.png ├── load_unpacked_edge.png ├── developer_mode_chrome.png ├── developer_mode_edge.png └── load_unpacked_chrome.png ├── CONTRIBUTING.md ├── LICENSE ├── SECURITY.md ├── CODE_OF_CONDUCT.md └── README.md /src/icons/icon-128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dheerajdlalwani/back-to-work/HEAD/src/icons/icon-128.png -------------------------------------------------------------------------------- /src/icons/icon-16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dheerajdlalwani/back-to-work/HEAD/src/icons/icon-16.png -------------------------------------------------------------------------------- /src/icons/icon-32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dheerajdlalwani/back-to-work/HEAD/src/icons/icon-32.png -------------------------------------------------------------------------------- /src/icons/icon-48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dheerajdlalwani/back-to-work/HEAD/src/icons/icon-48.png -------------------------------------------------------------------------------- /src/icons/icon-64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dheerajdlalwani/back-to-work/HEAD/src/icons/icon-64.png -------------------------------------------------------------------------------- /src/icons/icon-96.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dheerajdlalwani/back-to-work/HEAD/src/icons/icon-96.png -------------------------------------------------------------------------------- /static/github_preview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dheerajdlalwani/back-to-work/HEAD/static/github_preview.png -------------------------------------------------------------------------------- /static/load_unpacked_edge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dheerajdlalwani/back-to-work/HEAD/static/load_unpacked_edge.png -------------------------------------------------------------------------------- /static/developer_mode_chrome.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dheerajdlalwani/back-to-work/HEAD/static/developer_mode_chrome.png -------------------------------------------------------------------------------- /static/developer_mode_edge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dheerajdlalwani/back-to-work/HEAD/static/developer_mode_edge.png -------------------------------------------------------------------------------- /static/load_unpacked_chrome.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dheerajdlalwani/back-to-work/HEAD/static/load_unpacked_chrome.png -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 |

Contributing guidelines

2 | 3 |
4 | 5 | -------------------------------------------------------------------------------- /src/popup/popup.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 16 | 17 |
18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/icons/icon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Back To Work", 3 | 4 | "description": "Get back to doing what you're supposed to be doing with Back To Work", 5 | 6 | "author": "Dheeraj Lalwani", 7 | 8 | "version": "0.0.1", 9 | 10 | "manifest_version": 3, 11 | 12 | "background": { 13 | "service_worker": "background.js", 14 | "type": "module" 15 | }, 16 | 17 | "options_page": "options/options.html", 18 | 19 | "permissions": ["storage", "tabs", "declarativeNetRequest"], 20 | 21 | "action": { 22 | "default_popup": "popup/popup.html", 23 | "default_icon": { 24 | "16": "icons/icon-16.png", 25 | "32": "icons/icon-32.png", 26 | "48": "icons/icon-48.png", 27 | "96": "icons/icon-96.png", 28 | "128": "icons/icon-128.png" 29 | }, 30 | "default_title": "Back To Work" 31 | }, 32 | 33 | "icons": { 34 | "16": "icons/icon-16.png", 35 | "32": "icons/icon-32.png", 36 | "48": "icons/icon-48.png", 37 | "96": "icons/icon-96.png", 38 | "128": "icons/icon-128.png" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/popup/quotes.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "quote": "Always remember, your focus determines your reality.", 4 | "author": "George Lucas" 5 | }, 6 | { 7 | "quote": "I don't focus on what I'm up against. I focus on my goals and I try to ignore the rest.", 8 | "author": "Venus Williams" 9 | }, 10 | { 11 | "quote": "The successful warrior is the average man, with laser-like focus.", 12 | "author": "Bruce Lee" 13 | }, 14 | { 15 | "quote": "The secret of change is to focus all of your energy, not on fighting the old, but on building the new.", 16 | "author": "Socrates" 17 | }, 18 | { 19 | "quote": "Our focus is our future and what we focus on will multiply in our life.", 20 | "author": "David DeNotaris" 21 | }, 22 | { 23 | "quote": "Focus on the possibilities for success, not on the potential for failure.", 24 | "author": "Napoleon Hill" 25 | }, 26 | { 27 | "quote": "The secret of change is to focus all of your energy, not on fighting the old, but on building the new.", 28 | "author": "Socrates" 29 | } 30 | ] 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Dheeraj Lalwani 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | I am relatively very new to web-extension development & I am not a security expert, nor am I an expert at developing web-based extensions. So, if you do find any vulnerabilities, high risk or low risk, please please do send them my way. I shall try my best to patch them as soon as possible. User safety, security & privacy is my utmost priority. 4 | 5 | ## NO LIABILITY FOR DAMAGES 6 | 7 | In no event shall the author of this Software be liable for any special, consequential, incidental or indirect damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or any other pecuniary loss) arising out of the use of or inability to use this product, even if the Author of this Software is aware of the possibility of such damages and known defects. 8 | 9 | ## Supported Versions 10 | 11 | | Version | Supported | 12 | | :-----: | :-------: | 13 | | 0.0.1 | ✅ | 14 | | 0.0.2 | ✅ | 15 | 16 | ## Reporting a Vulnerability 17 | 18 | If you do happen to find a vulnerability, please feel free to shoot me an email or send me a direct message on Twitter or LinkedIn. My DMs are always open. My socials 👇🏼 19 | 20 | - [Email - lalwanidheeraj1234+BackToWork@gmail.com](lalwanidheeraj1234+BackToWork@gmail.com) 21 | - [Twitter - DhiruCodes](https://twitter.com/DhiruCodes) 22 | - [LinkedIn - lalwanidheeraj](https://www.linkedin.com/in/lalwanidheeraj) 23 | -------------------------------------------------------------------------------- /src/background.js: -------------------------------------------------------------------------------- 1 | console.log("Get Back To Work, NOW 😡"); 2 | 3 | // Setting initial mode as Chill 4 | let mode = "Chill"; 5 | chrome.runtime.onInstalled.addListener(() => { 6 | console.log("Beginning to set default mode to 'Chill'."); 7 | chrome.storage.sync.set({ mode }); 8 | chrome.storage.sync.get("blockedWebsites", ({ blockedWebsites }) => { 9 | if (blockedWebsites === undefined) { 10 | // checking if there is a list of empty websites in storage. if not initializing an empty list. 11 | console.log("ha bhai, blockedWebsites nahi hai list me."); 12 | let blockedWebsites = []; 13 | chrome.storage.sync.set({ blockedWebsites }); 14 | } 15 | }); 16 | chrome.declarativeNetRequest.getDynamicRules((rules) => { 17 | // removing old persisted dynamic rules from storage 18 | console.log( 19 | "Hello, here in the service worker. Deleting the old persisted rules." 20 | ); 21 | let rulesToBeDeleted = []; 22 | for (let i = 0; i < rules.length; i++) { 23 | rulesToBeDeleted.push(rules[i].id); 24 | } 25 | console.log("Rules to be deleted: " + rulesToBeDeleted); 26 | chrome.declarativeNetRequest.updateDynamicRules( 27 | { 28 | removeRuleIds: rulesToBeDeleted, 29 | }, 30 | () => { 31 | console.log("Done deleting 🥰"); 32 | } 33 | ); 34 | }); 35 | // showing options page. TODO make an onboarding page. 36 | chrome.tabs.create({ 37 | url: chrome.runtime.getURL("options/options.html"), 38 | }); 39 | }); 40 | -------------------------------------------------------------------------------- /src/popup/popup.css: -------------------------------------------------------------------------------- 1 | @import url("https://fonts.googleapis.com/css2?family=Manrope:wght@200;300;400;500;600;700;800&display=swap"); 2 | 3 | * { 4 | padding: 0; 5 | margin: 0; 6 | box-sizing: border-box; 7 | } 8 | 9 | html, 10 | body { 11 | width: 500px; 12 | font-family: "Manrope", sans-serif; 13 | display: flex; 14 | flex-direction: column; 15 | /* align-items: center; */ 16 | background-color: #e7efff; 17 | color: #000000; 18 | } 19 | 20 | #popup_header { 21 | display: flex; 22 | align-items: center; 23 | justify-content: space-around; 24 | margin: 1em; 25 | } 26 | 27 | #popup_header > img { 28 | margin: 10px; 29 | width: 75px; 30 | height: auto; 31 | filter: drop-shadow(0 0 7px #1f283f); 32 | } 33 | 34 | #header_content { 35 | display: flex; 36 | flex-direction: column; 37 | } 38 | 39 | #header_content > #main_title { 40 | font-size: 6vw; 41 | font-weight: 600; 42 | } 43 | 44 | #header_content > #sub_title { 45 | font-size: 4vw; 46 | font-weight: 400; 47 | font-style: italic; 48 | } 49 | 50 | #options_page { 51 | margin: 10px; 52 | padding: 10px; 53 | font-size: 3vw; 54 | font-weight: 700; 55 | background-color: #000e24; 56 | color: #ffffff; 57 | border: none; 58 | border-radius: 5px; 59 | cursor: pointer; 60 | } 61 | 62 | #mode_button { 63 | width: 30vw; 64 | margin: 15px; 65 | padding: 15px; 66 | font-size: 25px; 67 | font-weight: 700; 68 | background-color: #e7efff; 69 | color: #1f283f; 70 | border: none; 71 | border-radius: 5px; 72 | cursor: pointer; 73 | align-self: center; 74 | } 75 | 76 | .chill_mode_background { 77 | background: rgb(110, 231, 183); 78 | background: radial-gradient( 79 | circle, 80 | rgba(110, 231, 183, 1) 0%, 81 | rgba(52, 211, 153, 1) 25%, 82 | rgba(16, 185, 129, 1) 50%, 83 | rgba(5, 150, 105, 1) 100% 84 | ); 85 | color: #000000; 86 | } 87 | .work_mode_background { 88 | background: rgb(248, 113, 113); 89 | background: radial-gradient( 90 | circle, 91 | rgba(248, 113, 113, 1) 0%, 92 | rgba(248, 113, 113, 1) 25%, 93 | rgba(239, 68, 68, 1) 75%, 94 | rgba(239, 68, 68, 1) 100% 95 | ); 96 | } 97 | 98 | #quote_section { 99 | display: flex; 100 | flex-direction: column; 101 | align-items: center; 102 | justify-content: center; 103 | font-size: 1.5em; 104 | text-align: center; 105 | background-color: #000e24; 106 | color: #e7efff; 107 | border-radius: 15px 15px 0 0; 108 | } 109 | 110 | .quote { 111 | padding: 1em; 112 | } 113 | 114 | .author { 115 | font-weight: 700; 116 | } 117 | -------------------------------------------------------------------------------- /src/options/options.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Back To Work 9 | 10 | 11 | 17 | 44 | 45 |
46 | logo 47 |
48 |

Back to work

49 |

Get shit done ☑️

50 |
51 |
52 |
53 |

- Your addictive websites -

54 |
55 | 61 | 62 |
63 |
64 | 65 |
66 |
67 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | - Using welcoming and inclusive language 18 | - Being respectful of differing viewpoints and experiences 19 | - Gracefully accepting constructive criticism 20 | - Focusing on what is best for the community 21 | - Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | - The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | - Trolling, insulting/derogatory comments, and personal or political attacks 28 | - Public or private harassment 29 | - Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | - Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at lalwanidheeraj1234@gmail.com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq -------------------------------------------------------------------------------- /src/options/options.js: -------------------------------------------------------------------------------- 1 | let list = document.querySelector("#list"); 2 | console.log(list); 3 | 4 | document.addEventListener("DOMContentLoaded", () => { 5 | console.log("Load ho gaya window."); 6 | chrome.storage.sync.get("blockedWebsites", ({ blockedWebsites }) => { 7 | if (blockedWebsites.length == 0) { 8 | console.log("ha bhai, undefined bata raha hai."); 9 | let emptyListMessage = `

You have added no websites. Add now

`; 10 | list.innerHTML = emptyListMessage; 11 | return; 12 | } 13 | console.log(blockedWebsites); 14 | let listItems = ""; 15 | // inserting the buttons links & delete buttons on the page. 16 | for (let i = 0; i < blockedWebsites.length; i++) { 17 | listItems += `
  • ${blockedWebsites[i]}
  • `; 18 | } 19 | list.innerHTML = listItems; 20 | let deleteButtons = document.querySelectorAll(".delete_button"); 21 | for (let j = 0; j < deleteButtons.length; j++) { 22 | // implementing the delete website logic 23 | deleteButtons[j].addEventListener("click", () => { 24 | chrome.storage.sync.get("mode", ({ mode }) => { 25 | // checking if mode is work. 26 | if (mode === "Work") { 27 | alert("Cannot delete when in work mode!"); // TODO while refactoring, replace alert with a modal or a message toast. 28 | } else { 29 | let btnToBeDeleted = deleteButtons[j].value; 30 | console.log(btnToBeDeleted); 31 | chrome.declarativeNetRequest.getDynamicRules((rules) => { 32 | for (let k = 0; k < rules.length; j++) { 33 | if ( 34 | rules[k].condition.urlFilter === 35 | blockedWebsites[btnToBeDeleted] 36 | ) { 37 | chrome.declarativeNetApi.updateDynamicRules( 38 | { 39 | removeRuleIds: [rules[k].id], 40 | }, 41 | () => { 42 | console.log( 43 | "Deleted: " + blockedWebsites[btnToBeDeleted] 44 | ); 45 | } 46 | ); 47 | } 48 | } 49 | }); 50 | blockedWebsites.splice(btnToBeDeleted, 1); 51 | chrome.storage.sync.set({ blockedWebsites }); 52 | location.reload(); 53 | } 54 | }); 55 | }); 56 | } 57 | }); 58 | }); 59 | 60 | // implementing logic for adding new website. 61 | let addButton = document.querySelector("#add_button"); 62 | console.log(addButton); 63 | const domain_dot_tld_regex = /\w+\.[a-zA-B]+/g; 64 | addButton.addEventListener("click", () => { 65 | console.log("Ha bhai click ho gaya..."); 66 | chrome.storage.sync.get("mode", ({ mode }) => { 67 | // checking if mode is work. 68 | if (mode === "Work") { 69 | alert("Cannot add when in work mode!"); // TODO while refactoring, replace alert with a modal or a message toast. 70 | } else { 71 | let newWebsite = document.querySelector(".new_website"); 72 | if (newWebsite.value.trim() !== "") { 73 | if (domain_dot_tld_regex.test(newWebsite.value)) { 74 | chrome.storage.sync.get("blockedWebsites", ({ blockedWebsites }) => { 75 | if (blockedWebsites.indexOf(newWebsite.value) === -1) { 76 | blockedWebsites.push(newWebsite.value); 77 | chrome.storage.sync.set({ blockedWebsites }); 78 | location.reload(); 79 | } else { 80 | newWebsite.value = ""; 81 | newWebsite.placeholder = "Website already exists!"; 82 | newWebsite.classList.add("new_website_field_error"); 83 | } 84 | }); 85 | } else { 86 | newWebsite.value = ""; 87 | newWebsite.placeholder = 88 | "Error. Please enter a valid website domain."; 89 | newWebsite.classList.add("new_website_field_error"); 90 | } 91 | } else { 92 | newWebsite.value = ""; 93 | newWebsite.placeholder = "Field is empty!"; 94 | newWebsite.classList.add("new_website_field_error"); 95 | } 96 | } 97 | }); 98 | }); 99 | -------------------------------------------------------------------------------- /src/options/options.css: -------------------------------------------------------------------------------- 1 | @import url("https://fonts.googleapis.com/css2?family=Manrope:wght@200;300;400;500;600;700;800&display=swap"); 2 | 3 | * { 4 | padding: 0; 5 | margin: 0; 6 | box-sizing: border-box; 7 | } 8 | 9 | html, 10 | body { 11 | font-family: "Manrope", sans-serif; 12 | background-color: #e7efff; 13 | color: #000000; 14 | } 15 | 16 | header { 17 | display: flex; 18 | flex-direction: row; 19 | align-items: center; 20 | margin: 3vw; 21 | align-content: space-around; 22 | } 23 | 24 | header > img { 25 | margin: 10px; 26 | filter: drop-shadow(0 0 7px #1f283f); 27 | margin-right: 50px; 28 | } 29 | 30 | #header_content > #main_title { 31 | font-size: 45px; 32 | font-weight: 600; 33 | } 34 | 35 | #header_content > #sub_title { 36 | font-size: 25px; 37 | font-weight: 400; 38 | font-style: italic; 39 | } 40 | 41 | .new_website { 42 | border-radius: 10px; 43 | width: 70%; 44 | margin: 15px; 45 | padding: 10px 15px; 46 | border: none; 47 | outline: none; 48 | font-size: 20px; 49 | text-align: center; 50 | filter: drop-shadow(0 0 2px #1f283f); 51 | } 52 | 53 | .new_website:focus { 54 | filter: drop-shadow(0 0 7px #006eff); 55 | } 56 | 57 | .new_website_field_error { 58 | border: solid rgb(255, 93, 93) 2px; 59 | } 60 | .new_website_field_error::placeholder { 61 | color: rgb(255, 93, 93); 62 | } 63 | 64 | #list_container { 65 | display: flex; 66 | flex-direction: column; 67 | align-items: center; 68 | } 69 | 70 | #list_container > h3 { 71 | font-size: 30px; 72 | font-size: clamp(25px, 3vw, 35px); 73 | margin: 0.5em; 74 | } 75 | 76 | #list { 77 | font-size: 20px; 78 | list-style-type: none; 79 | width: 100%; 80 | display: flex; 81 | flex-direction: column; 82 | justify-content: center; 83 | align-items: center; 84 | } 85 | 86 | #list > li { 87 | display: flex; 88 | justify-content: space-evenly; 89 | align-items: center; 90 | width: 75vw; 91 | width: clamp(500px, 65vw, 900px); 92 | } 93 | 94 | #list > li > span { 95 | width: 70%; 96 | margin: 15px; 97 | padding: 10px 15px; 98 | border-radius: 10px; 99 | text-align: center; 100 | text-decoration: none; 101 | background-color: #afcaff; 102 | color: #000000; 103 | outline: none; 104 | } 105 | 106 | #list > li > span:focus, 107 | #list > li > button:focus { 108 | filter: drop-shadow(0 0 7px #006eff); 109 | } 110 | 111 | #empty_message { 112 | margin: 1em; 113 | } 114 | 115 | #add_new { 116 | display: flex; 117 | justify-content: space-evenly; 118 | align-items: center; 119 | width: 75vw; 120 | width: clamp(500px, 65vw, 900px); 121 | } 122 | 123 | #add_button { 124 | width: 15%; 125 | border-radius: 10px; 126 | padding: 0.5em; 127 | margin: 0.5em; 128 | font-size: 20px; 129 | border: none; 130 | outline: none; 131 | background-color: #000e24; 132 | color: #afcaff; 133 | filter: drop-shadow(0 0 2px #1f283f); 134 | cursor: pointer; 135 | } 136 | 137 | #add_button:focus { 138 | filter: drop-shadow(0 0 7px #006eff); 139 | } 140 | 141 | #list_wrapper { 142 | display: flex; 143 | flex-direction: row; 144 | width: 100%; 145 | align-items: center; 146 | justify-content: center; 147 | } 148 | 149 | #delete_buttons { 150 | list-style-type: none; 151 | } 152 | 153 | .delete_button { 154 | width: 15%; 155 | border-radius: 10px; 156 | padding: 0.5em; 157 | margin: 0.5em; 158 | font-size: 20px; 159 | border: none; 160 | outline: none; 161 | background-color: #afcaff; 162 | color: #000e24; 163 | filter: drop-shadow(0 0 2px #1f283f); 164 | cursor: pointer; 165 | } 166 | 167 | footer { 168 | display: flex; 169 | flex-direction: column; 170 | text-align: center; 171 | align-items: center; 172 | justify-content: center; 173 | font-size: 20px; 174 | margin-top: 1em; 175 | padding: 1em; 176 | } 177 | 178 | footer a { 179 | color: #000e24; 180 | font-weight: 700; 181 | } 182 | 183 | .github-corner:hover .octo-arm { 184 | animation: octocat-wave 560ms ease-in-out; 185 | } 186 | 187 | @keyframes octocat-wave { 188 | 0%, 189 | 100% { 190 | transform: rotate(0); 191 | } 192 | 193 | 20%, 194 | 60% { 195 | transform: rotate(-25deg); 196 | } 197 | 198 | 40%, 199 | 80% { 200 | transform: rotate(10deg); 201 | } 202 | } 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
    2 | 3 |

    4 | 5 |

    6 | 7 |

    Back to Work

    8 |
    9 | 10 |

    11 | A simple browser extension, intended to get you Back To Work when you start slacking off to one of those really addictive sites. 12 |

    13 | 14 |
    15 | 16 |

    How to install?

    17 | 18 |
      19 |
    1. 20 | Clone the repository or download the latest release archive from here. 21 |
    2. 22 |
    3. 23 | If you are on Google Chrome Browser, open new tab & type: chrome://extensions or if you are on Microsoft Edge Browser, type: edge://extensions. 24 |
    4. 25 |
    5. 26 | Look for the Developer mode toggle & turn it on if it's not already. 27 |
    6. 28 |
    7. 29 | Here's where to find it in - 30 | 36 |
    8. 37 |
    9. 38 | Next, click on Load unpacked. 39 |
    10. 40 |
    11. 41 | Here's where to find it in - 42 | 48 |
    12. 49 |
    13. 50 | Then navigate to the extracted folder if you downloaded it from the Releases page or to the src folder if you have cloned the source code. 51 |
    14. 52 |
    15. 53 | There you go! Your extension is installed. 54 |
    16. 55 |
    56 | 57 |
    58 | 59 |

    What does it really do?

    60 | 61 |

    62 | Well thats easy to understand. There are 2 modes. 63 |

      64 |
    1. Work
    2. 65 |
    3. Chill
    4. 66 |
    67 | When you switch to work mode, it asks you to list all the websites that you are addicted to.For example: YouTube, Instagram, Twitter... And it locks you out of those websites. 68 |

    69 | 70 |
    71 | 72 |

    For how long? How do I unlock them? I need to have some fun at least...

    73 | 74 |

    75 | The extension asks you to choose one out of the two unlocking modes- 76 |

    77 | 78 |

    Time Based

    79 | 80 |

    81 | In time based locking mode. It will ask you for how long you wish to lock these websites and they will be forbidden. If you still try to visit these websites, you shall be redirected to a standard page, reminding you to get back to your tasks or redirect you to a website of your choice. 82 |

    83 | 84 |

    Password Based

    85 |

    86 | In password based unlocking, you shall be asked to type in an unlocking password which can be set by someone else and can be unlocked by them once you are done with your work. 87 |

    88 | 89 |
    90 | 91 |

    Compatibility

    92 |

    93 | Currently, this extension works only on Chrome, Edge and hopefully other Chromium based browsers. But one of the long term goals for this project is to be cross browser compatible. If you wish to help me make them compatible across browsers, feel free to open a new issue or shoot me an email or direct message me at any of my socials 👇🏼 94 |

    99 |

    100 | 101 |
    102 | 103 |

    Contributing

    104 | 105 | 109 | 110 |
    111 | 112 |

    Code of Conduct

    113 | 114 | Please be mindful of the [Code of Conduct](CODE_OF_CONDUCT.md) while contributing and interacting. 115 | -------------------------------------------------------------------------------- /src/popup/popup.js: -------------------------------------------------------------------------------- 1 | let modeButton = document.getElementById("mode_button"); 2 | let optionsPageButton = document.getElementById("options_page"); 3 | console.log("Yo bro. From popup.js"); 4 | 5 | // Initializing background color as per default mode 6 | chrome.storage.sync.get("mode", ({ mode }) => { 7 | console.log("popup.js line 7, mode = ", mode); 8 | modeButton.innerHTML = mode; 9 | if (mode === "Chill") { 10 | document.getElementsByTagName("body")[0].className = 11 | "chill_mode_background"; 12 | modeButton.innerHTML = "Chilling..."; 13 | } else { 14 | document.getElementsByTagName("body")[0].className = "work_mode_background"; 15 | modeButton.innerHTML = "Working."; 16 | } 17 | // modeButton.innerHTML = mode; 18 | console.log("Default mode was: ", mode); 19 | }); 20 | 21 | function changeMode() { 22 | console.log("Button clicked."); 23 | chrome.storage.sync.get("mode", ({ mode }) => { 24 | if (mode === "Chill") { 25 | mode = "Work"; 26 | modeButton.innerHTML = "Working."; 27 | document.getElementsByTagName("body")[0].className = 28 | "work_mode_background"; 29 | console.log("Mode was 'Chill'. Now setting to 'Work'."); 30 | chrome.storage.sync.get("blockedWebsites", ({ blockedWebsites }) => { 31 | console.log("The following websites shall be blocked."); 32 | blockedWebsites.forEach((url, index) => { 33 | // actually updating the rules. 34 | let id = index + 1; 35 | chrome.declarativeNetRequest.updateDynamicRules({ 36 | addRules: [ 37 | { 38 | id: id, 39 | priority: 1, 40 | action: { type: "block" }, 41 | condition: { 42 | urlFilter: url, 43 | resourceTypes: [ 44 | "main_frame", 45 | "sub_frame", 46 | "xmlhttprequest", 47 | "other", 48 | "script", 49 | "stylesheet", 50 | ], 51 | }, 52 | }, 53 | ], 54 | removeRuleIds: [id], 55 | }); 56 | }); 57 | }); 58 | } else { 59 | mode = "Chill"; 60 | modeButton.innerHTML = "Chilling..."; 61 | document.getElementsByTagName("body")[0].className = 62 | "chill_mode_background"; 63 | console.log("Mode was 'Work'. Now setting to 'Chill'."); 64 | chrome.declarativeNetRequest.getDynamicRules((rules) => { 65 | console.log( 66 | "Hello, here in popup.js, deleting rules because work mode is turned off." 67 | ); 68 | // deleting rules when mode changed to chill. 69 | let rulesToBeDeleted = []; 70 | for (let i = 0; i < rules.length; i++) { 71 | rulesToBeDeleted.push(rules[i].id); 72 | } 73 | console.log("Rules to be deleted: " + rulesToBeDeleted); 74 | chrome.declarativeNetRequest.updateDynamicRules( 75 | { 76 | removeRuleIds: rulesToBeDeleted, 77 | }, 78 | () => { 79 | console.log("Done deleting 🥰"); 80 | } 81 | ); 82 | }); 83 | } 84 | chrome.storage.sync.set({ mode }); 85 | }); 86 | } 87 | 88 | let openOptionsPage = () => { 89 | console.log("Opening options page"); 90 | chrome.tabs.create({ 91 | url: chrome.runtime.getURL("options/options.html"), 92 | }); 93 | }; 94 | 95 | // Note to self: Refactor this with a better approach using