在 Tampermonkey (竄改猴)新增一個腳本,然後將以下程式碼貼上: ```javascript= // ==UserScript== // @name Work Time Limit // @author Steven SHIH // @namespace http://tampermonkey.net/ // @version 1.0 // @description Block access to specific websites during working hours (8:30 - 17:30) // @match *://www.facebook.com/* // @match *://www.ptt.cc/* // @match *://forum.gamer.com.tw* // @grant none // ==/UserScript== (function() { 'use strict'; // 設定工作時間範圍 const startTime = { hour: 8, minute: 30 }; const endTime = { hour: 17, minute: 30 }; // 取得當前時間 const now = new Date(); const currentHour = now.getHours(); const currentMinute = now.getMinutes(); const currentDay = now.getDay(); // 0 = 週日, 1 = 週一, ..., 6 = 週六 // 判斷是否是工作日(週一到週五) const isWeekday = currentDay >= 1 && currentDay <= 5; // 判斷是否在工作時間內 const isWithinWorkHours = (currentHour > startTime.hour || (currentHour === startTime.hour && currentMinute >= startTime.minute)) && (currentHour < endTime.hour || (currentHour === endTime.hour && currentMinute < endTime.minute)); // 如果在工作時間內,阻止訪問並顯示訊息 if (isWeekday && isWithinWorkHours) { document.body.innerHTML = ` <div style='text-align: center;'> <img src='https://today-obs.line-scdn.net/0hERA6M8EUGn18TzMHydJlKkYZGRJPIwl-GHlLfj8hREkGfwh4SXsFE19LQx9ULF0jFSlRHlBGAUwDe1V-F3oF/w1200' alt='專心工作' style='max-width: 100%; height: auto;' /> </div> <h1 style='text-align: center; color: cyan; font-family: Noto Sans JP;'>目前是工作時間 (8:30 - 17:30),請專心!</h1> <h2 style='text-align: center; color: cyan; font-family: Noto Sans JP;'>It's working hours (8:30 - 17:30), please pay attention !</h2> `; document.body.style.backgroundColor = "#000000"; } })(); ``` ==@match==:要讓此腳本生效的網站。 腳本執行後,在設定的時間內 (我自己是設定8:30 - 17:30),訪問 ==@match== 寫上的網址時,會跳出以下資訊:  ,
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up