Repository: sologgfun/drinkNow Branch: master Commit: 77d04dfd7bb3 Files: 7 Total size: 11.9 KB Directory structure: gitextract_u4g1_o8h/ ├── README.md ├── background.html ├── js/ │ ├── background.js │ ├── content-script.js │ └── popup.js ├── manifest.json └── popup.html ================================================ FILE CONTENTS ================================================ ================================================ FILE: README.md ================================================ 感觉工作之后写代码经常忘记喝水,而且我本身因为以前经常不吃早饭,有点胆结石,医生也提醒说要多喝水多运动,但是写代码集中精神之后就经常忘记了。。 前段时间公司体检后发现颈椎有点前倾,明明才刚毕业几个月,,大家一起注意身体健康吧!下面是插件的详细内容~ **干杯!妈妈再也不担心我不喝水了!** v0.08更新!2019-9-7 13.04 修复浏览器console报错的小bug🙇‍ v0.07更新!11-9 19.40 修复了小鸭子倒着游的重大bug🙇‍ v0.06更新!10-19 15.00 之前计时重复了,30分钟喝一杯了,我对不起大家!小鸭子替我道歉🙇 v0.05更新!10-18 19:55 1.白天点击refresh小鸭子变大,晚上点击小鸭子会变小(否则小鸭子似乎经常遭到毒手变的太大回不去! 2.提示出来之后点击喝水按钮后就刷新计时,不需要在标签里点击刷新啦! 3.谢谢大家的支持! *年轻人的第一个chrome插件!* *关注大家的身体健康;* *rua!!!* **主要功能:** ①通过标签提醒距离上次喝水已经过了多久 ②点击右上角刷新时间 ③点击太阳切换白昼/黑夜暂停时间 ④60分钟会提示并且标签会变色 (其实这个是一个养成类的游戏,小鸭子喝水会变大,不及时喝水会变小。哈哈哈哈哈哈 (感谢小朋友🐏医生) The first chrome plugin for young people! Teach young people write plugins at the same time; Pay attention to your health; Rua!!! The main function: ①Through the badge to remind you how long it has been since drinking the last time ②click the top right corner to refresh the countdown ③click the sun to switch to the day/night to pause time losing ④every 60 minutes will prompt at once and the label will change color (In fact, this is a game , the ducklings will get bigger when you drink water and refresh, and they will get smaller if they don’t drink in time. Hahahahahaha (Thanks to doctors 🐏 - the one I love!❤) ![day](http://p0.meituan.net/dpgroup/e6c968d702f336e8d2df47f4adf7ec0639097.png) ![night](http://p1.meituan.net/dpgroup/a95fc0ee6e4ec1cc62a3b21e2271e6eb42003.png) chrome插件地址:https://chrome.google.com/webstore/search/%E5%B9%B2%E6%9D%AF?hl=zh-CN github地址:https://github.com/sologgfun/drinkNow ================================================ FILE: background.html ================================================ background ================================================ FILE: js/background.js ================================================ var count = 0; var winWidth = 1440; var winHeight = 860; var notificationId; var countdownId = 0; var light = true; var duckwidth = 15; chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) { winWidth = request.winWidth; winHeight = request.winHeight; sendResponse(''); }); function duckbecomeslim() { duckwidth = duckwidth - 4; } function duckbecomefat() { duckwidth = duckwidth + 2; } function smallduck() { duckwidth = duckwidth - 2; } function getduckwidth() { return duckwidth; } function checklight() { return light } function turnlight() { light = !light; } //计时器,在后台默默计时 function timer() { //黑夜停止计时 if (!light) { return count / 36 } if (count < 3600) { count++; //给浏览器右上角图标加上计时badge chrome.browserAction.setBadgeText({ text: Math.floor(count / 60) + '' }); chrome.browserAction.setBadgeBackgroundColor({ color: "#70d2c9" }); } //60分钟通知喝水! if (count == 3600) { duckbecomeslim(); notificationAction(); count++; } if (count >= 3600) { //图标改成红色和sos文案! chrome.browserAction.setBadgeText({ text: 'sos' }); chrome.browserAction.setBadgeBackgroundColor({ color: [255, 0, 0, 255] }); } return count / 36 } function refresh() { count = 0; //清除五分钟倒计时 window.clearInterval(countdownId); } var fivemin = 0; var Countdown = function () { fivemin++; if (fivemin == 300) { notificationAction(); fivemin = 0; } }; function notificationAction() { //notification的id要清空,否则create的时候之前id没有清空则会失效 chrome.notifications.clear("1", (id) => { }); chrome.notifications.create("1", { type: 'basic', iconUrl: 'img/logo.png', title: '快喝水!', buttons: [{ title: "喝水", iconUrl: 'img/yellowsmile.png' }, { title: "等会儿", iconUrl: 'img/redsmile.png' }], message: '已经一个小时没喝水了!小鸭子渴死了!' }); } chrome.notifications.onButtonClicked.addListener(function (id, btnIndex) { count = btnIndex ? count : 0; }); function getWandH() { var WandH = { winWidth: winWidth, winHeight: winHeight } return WandH } setInterval(timer, 1000); ================================================ FILE: js/content-script.js ================================================ var winWidth, winHeight; //屏幕分辨率版本 winWidth = window.screen.width; winHeight = window.screen.height; chrome.runtime.sendMessage({ winWidth: winWidth, winHeight: winHeight }, function (response) { }); ================================================ FILE: js/popup.js ================================================ var bg = chrome.extension.getBackgroundPage(); var getHtml = document.getElementsByTagName("html")[0]; var getClock = document.getElementById("img"); var getImg = document.getElementById("clock"); var progressbar = document.getElementById("progressbar"); var light = bg.checklight(); var check = document.getElementById("toggle"); var duckwidth = bg.getduckwidth(); //true为黑夜 getClock.style.width = duckwidth + "%"; if (!light) { getImg.innerText = `大魔法让时间停止了!`; check.checked = true; getHtml.id = "htmlbg2"; progressbar.id = "progressbar2"; } //自适应窗口大小 var WandH = bg.getWandH(); getHtml.style.width = WandH.winWidth * 1 / 5 + "px"; getHtml.style.height = WandH.winHeight * 1 / 7 + "px"; console.log(getHtml.style.width); //文字提示和小鸭子前进 getClock.style.left = `${bg.timer() - 10}%`; if (Math.floor(bg.timer() * 36 / 60) == 60) { getImg.innerText = `快给我水给我水给我水!`; getClock.src = "../img/dead.png"; } //水向前变色 document.getElementsByClassName("bar")[0].style.width = `${bg.timer()}%`; document.getElementById("refresh").addEventListener("click", function (e) { //刷新计数,小鸭子跑回去 bg.refresh(); if (!light) { getClock.style.width = duckwidth - 2 + "%"; bg.smallduck(); duckwidth = duckwidth - 2; } else { getClock.style.width = duckwidth + 2 + "%"; bg.duckbecomefat(); duckwidth = duckwidth + 2; } getClock.src = "../img/imok.png"; getImg.innerText = `哧溜哧溜~喝水了!`; getClock.style.left = `-10%`; document.getElementsByClassName("bar")[0].style.width = `0%`; }); //点击太阳时改变样式,并且让background.js中的计数暂停 document.getElementById("sun").addEventListener("click", function (e) { //暂停计数 bg.turnlight(); light = !light; //样式改变 if (bg.checklight()) { getImg.innerText = ``; check.checked = false; getHtml.id = "htmlbg"; progressbar.id = "progressbar"; } else { getImg.innerText = `大魔法让时间停止了!`; check.checked = true; getHtml.id = "htmlbg2"; progressbar.id = "progressbar2"; } }); ================================================ FILE: manifest.json ================================================ { "manifest_version": 2, "name": "干杯!cheers~!", "version": "0.0.8", "description": "干杯!妈妈再也不担心我不喝水了!cheers!Mom is no longer worried that I will not drink water!", "icons": { "16": "./img/logo.png", "48": "./img/logo.png", "128": "./img/logo.png" }, "permissions": [ "notifications", "webRequestBlocking", "storage" ], "background": { "page": "./background.html" }, "browser_action": { "default_icon": "./img/logo.png", "default_title": "drinkNow!", "default_popup": "./popup.html" }, "content_scripts": [ { "matches": [ "" ], "js": [ "js/content-script.js" ], "run_at": "document_start" } ] } ================================================ FILE: popup.html ================================================ drinknow
imok
imok