Greasy Fork 还支持 简体中文。

canvas_checkboxes

Add checkboxes to some items in canvas to keep track of what's been read/done.

目前為 2020-10-03 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        canvas_checkboxes
// @namespace   Violentmonkey Scripts
// @match       https://*.instructure.com/*/*/modules
// @match       https://*.instructure.com/*/*/assignments
// @grant       none
// @version     1.2.0
// @author      -
// @description Add checkboxes to some items in canvas to keep track of what's been read/done.
// ==/UserScript==

var actual_links = document.getElementsByClassName("ig-title");
var off_color = "#ffc4c4";
var on_color = "rgb(227, 251, 184)";

/* For assignments, depth is 3, for modules, depth is 4 */
function encolor(elt, color, depth) {
  if (depth === undefined) {
    var pieces = window.location.pathname.split("/");
    var final_slug = pieces[pieces.length - 1];
    if (final_slug == "assignments") {
      depth = 3;
    }
    else if (final_slug == "modules") {
      depth = 4;
    }
    else {
      depth = 0;
    }
  }
  var to_be_styled = elt;
  for (var i = 0; i < depth; i++) {
    to_be_styled = to_be_styled.parentElement;
  }
  to_be_styled.style.background = color;
}

function color_on(elt, depth) {
  encolor(elt, on_color, depth);
}

function color_off(elt, depth) {
  encolor(elt, off_color, depth);
}

function toggle(elt) {
  if (toggled_on(elt)) {
    toggle_off(elt);
  }
  else {
    toggle_on(elt);
  }
}


function toggle_on(elt) {
  localStorage["ccb_" + elt.href] = "clicked";
  color_on(elt);
}

function toggled_on(elt) {
  if (localStorage["ccb_" + elt.href] === undefined) {
    return false;
  }
  return true;
}

function toggle_off(elt) {
  delete localStorage["ccb_" + elt.href];
  color_off(elt);
}


function add_checkbox_assignment(elt) {
  var checkbox = document.createElement("input");
  checkbox.type = "checkbox";
  elt.children[0].children[0].children[1].insertBefore(checkbox, temp1.children[0].children[0].children[1].children[0].nextElementSibling)
  console.log(checkbox);
  console.log(elt);
}


function add_checkbox(elt) {
  var checkbox = document.createElement("input");
  checkbox.type = "checkbox";
  elt.parentElement.insertBefore(checkbox, elt.nextElementSibling);
  checkbox.addEventListener('change', function() {
    if (this.checked) {
      toggle_on(this.previousElementSibling);
    }
    else {
      toggle_off(this.previousElementSibling);
    }    
  });

  if (toggled_on(elt)) {
    color_on(elt);
    checkbox.checked = true;
  }
  else {
    color_off(elt);
    checkbox.checked = false;
  }
}


function main() {
  for (var i = 0; i < actual_links.length; i++) {
    var actual_link = actual_links[i];  
    add_checkbox(actual_link);
  }
}

main();