Skip to content

Instantly share code, notes, and snippets.

@applemango
Created February 3, 2024 01:37
Show Gist options
  • Save applemango/c742c131644769e77d65978b76424b7d to your computer and use it in GitHub Desktop.
Save applemango/c742c131644769e77d65978b76424b7d to your computer and use it in GitHub Desktop.
googleスプレッドシートのテンプレートにあるtodoで、完了済みにしたアイテムをランダムにオフにするプログラム
const numberToSheetPosition = (x, y) => {
const xL = ["A", "B", "C", "D"]
return `${xL[x]}${y+1}`
}
const findCheckedItems = () => {
const sheet = SpreadsheetApp.getActiveSheet()
const sheetValues = sheet.getDataRange().getValues();
const truePosition = sheetValues.reduce((acc, v, i)=> {
const [bool, label] = v
if(bool === true) {
return acc.concat(numberToSheetPosition(0, i))
}
return acc
},[])
return truePosition
}
const unCheckItem = (position) => {
const sheet = SpreadsheetApp.getActiveSheet()
sheet.getRange(position).setValue(false);
}
const canRunNow = () => {
const hour = new Date().getHours()
if(hour > 19 || hour < 10) {
return false
}
if(Math.random() > 0.5) {
return false
}
return true
}
const unCheckRandomCheckedPosition = () => {
if(!canRunNow()) return
const positions = findCheckedItems()
const randomPosition = positions[Math.floor(Math.random() * positions.length)]
unCheckItem(randomPosition)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment