AP Stats Name Converter

converts the dumb names into ones used in AP Stats

  1. // ==UserScript==
  2. // @name AP Stats Name Converter
  3. // @namespace Violentmonkey Scripts
  4. // @match http://www.ltcconline.net/greenl/java/Statistics/catStatProb/categorizingStatProblemsJavaScript.html*
  5. // @grant none
  6. // @version 1.0
  7. // @author bob-source
  8. // @description converts the dumb names into ones used in AP Stats
  9. // @license GPL-3.0-or-later
  10. // ==/UserScript==
  11. (function() {
  12. 'use strict';
  13. // Only run the script if we are on the expected page
  14. if (document.querySelector('input[name="quux[1]"]')) {
  15. // Mapping of original names to AP Stats terminology
  16. const nameMapping = {
  17. 'Confidence Interval for a Population Mean': 'One-sample t-interval for a mean',
  18. 'Confidence Interval for a Proportion': 'One-sample z-interval for a proportion',
  19. 'Confidence Interval for the Diff. Between 2 Means (Independent Samples)': 'Two-sample t-interval for the difference of means',
  20. 'Confidence Interval for Paired Data (Dependent Samples)': 'Paired t-interval for the mean difference',
  21. 'Confidence Interval for the Difference Between 2 Proportions': 'Two-sample z-interval for the difference of proportions',
  22. 'Hypothesis Test for a Population Mean': 'One-sample t-test for a mean',
  23. 'Hypothesis Test for a Population Proportion': 'One-sample z-test for a proportion',
  24. 'Hyp. Test for the Difference Between 2 Means (Independent Samples)': 'Two-sample t-test for the difference of means',
  25. 'Hyp. Test for Paired Data (Dependent Samples)': 'Paired t-test for the mean difference',
  26. 'Hyp. Test fro the Difference Between 2 Proportions': 'Two-sample z-test for the difference of proportions'
  27. };
  28.  
  29. // Function to replace text in all elements that could contain the statistical terms
  30. function updateAllElements() {
  31. // Process labels
  32. const labels = document.querySelectorAll('label');
  33. labels.forEach(label => {
  34. Object.keys(nameMapping).forEach(originalText => {
  35. if (label.textContent.includes(originalText)) {
  36. label.textContent = label.textContent.replace(originalText, nameMapping[originalText]);
  37. }
  38. });
  39. });
  40.  
  41. // Process divs
  42. const divs = document.querySelectorAll('div');
  43. divs.forEach(div => {
  44. // Only process text nodes directly in the div (not in child elements)
  45. for (let i = 0; i < div.childNodes.length; i++) {
  46. const node = div.childNodes[i];
  47. if (node.nodeType === Node.TEXT_NODE) {
  48. Object.keys(nameMapping).forEach(originalText => {
  49. if (node.textContent.includes(originalText)) {
  50. node.textContent = node.textContent.replace(originalText, nameMapping[originalText]);
  51. }
  52. });
  53. }
  54. }
  55. });
  56.  
  57. // Process text nodes after checkboxes
  58. for (let i = 1; i <= 15; i++) {
  59. const checkbox = document.querySelector(`input[name="quux[${i}]"]`);
  60. if (checkbox) {
  61. let nextNode = checkbox.nextSibling;
  62. if (nextNode && nextNode.nodeType === Node.TEXT_NODE) {
  63. Object.keys(nameMapping).forEach(originalText => {
  64. if (nextNode.textContent.includes(originalText)) {
  65. nextNode.textContent = nextNode.textContent.replace(originalText, " " + nameMapping[originalText]);
  66. }
  67. });
  68. }
  69. }
  70. }
  71.  
  72. // Process any other text elements or spans that might contain the text
  73. const spans = document.querySelectorAll('span');
  74. spans.forEach(span => {
  75. Object.keys(nameMapping).forEach(originalText => {
  76. if (span.textContent.includes(originalText)) {
  77. span.textContent = span.textContent.replace(originalText, nameMapping[originalText]);
  78. }
  79. });
  80. });
  81.  
  82. // Process paragraphs
  83. const paragraphs = document.querySelectorAll('p');
  84. paragraphs.forEach(p => {
  85. Object.keys(nameMapping).forEach(originalText => {
  86. if (p.textContent.includes(originalText)) {
  87. p.textContent = p.textContent.replace(originalText, nameMapping[originalText]);
  88. }
  89. });
  90. });
  91. console.log("code is ran");
  92. }
  93.  
  94. // Run the update function initially
  95. updateAllElements();
  96.  
  97. // Run it again after a short delay to handle any dynamic content
  98. setTimeout(updateAllElements, 1000);
  99.  
  100. // Set up a MutationObserver to handle dynamically added content
  101. const observer = new MutationObserver(function(mutations) {
  102. updateAllElements();
  103. });
  104.  
  105. // Start observing the document with the configured parameters
  106. observer.observe(document.body, {
  107. childList: true,
  108. subtree: true
  109. });
  110. }
  111. })();