Greasy Fork

Greasy Fork is available in English.

问卷星无障碍优化

问卷星无障碍优化脚本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name  问卷星无障碍优化
// @namespace    https://accjs.org/
// @version      0.1
// @description  问卷星无障碍优化脚本
// @author  杨永全
// @match  https://*.wjx.com/*
// @match  https://*.wjx.cn/*
// @match  https://*.wjx.top/*
// @grant  none
// ==/UserScript==

(function() {
cproc();
aamo(aproc);

document.addEventListener('keydown', function(e) {
let t = e.target || null;
if(e.keyCode == 32 || e.keyCode == 13) {
if(t.matches('.accjs-click')) {
t.click();
if(t.matches('textarea[province]')) {
setTimeout(function() {
var iframe = document.querySelector('iframe');
if(iframe != null) {
var select = iframe.contentDocument.querySelector('select');
if(select != null) {
select.focus();
}
}
}, 300);
}
}
}
}, null);

function aproc(records) {
document.querySelectorAll('.jqRadio, .jqCheckbox').forEach(function(el) {
let checked = el.matches('.jqChecked');
attr(el, 'aria-checked', checked);
});
}

function cproc() {
let titles = document.querySelectorAll('h1, .surveydescription, .div_title_cut_question, .div_title_question_all');
titles.forEach(function(el) {
let label = el.innerText;
attr(el, 'aria-label', label);
attr(el, 'tabindex', '0');
let pe = el.parentNode;
if(pe != null) {
pe.querySelectorAll('textarea, input').forEach(function(el) {
attr(el, 'aria-label', label);
});
}
});
if(titles.length > 0) {
titles[0].focus();
}

document.querySelectorAll('.jqRadio, .jqCheckbox').forEach(function(el) {
let label = el.parentNode.innerText || '';
attr(el, 'aria-label', label);
attr(el, 'aria-checked', 'false');
addClass(el, 'accjs-click');
let pe = el.parentNode;
if(pe != null) {
pe.querySelectorAll('label').forEach(function(el) {
attr(el, 'aria-hidden', 'true');
});
pe.querySelectorAll('input').forEach(function(el) {
attr(el, 'aria-label', label);
});
}
});

document.querySelectorAll('.jqRadio').forEach(function(el) {
attr(el, 'role', 'radio');
attr(el, 'tabindex', '-1');
});

document.querySelectorAll('.jqCheckbox').forEach(function(el) {
attr(el, 'role', 'checkbox');
});

document.querySelectorAll('.div_question').forEach(function(el) {
let radios = el.querySelectorAll('.jqRadio');
if(radios.length > 0) {
radios[0].setAttribute('tabindex', '0');
}
});

document.querySelectorAll('#divProgressBar').forEach(function(el) {
attr(el, 'tabindex', '0');
//attr(el, 'role', 'progressbar');
});

document.querySelectorAll('textarea[province]').forEach(function(el) {
attr(el, 'title', '按空格键或回车键打开地区选择对话框');
el.removeAttribute('aria-label');
addClass(el, 'accjs-click');
});

//end cproc function
}


function attr(el, key, val) {
el.setAttribute(key, val);
}

function addClass(el, classes) {
classes.split(' ').forEach(function(className) {
el.classList.add(className);
});
}

function aamo(proc) {
    var mo = new MutationObserver((records) => {
proc(records);
});
    mo.observe(document.body, {
      'attributes': true,
//'attributeOldValue': true,
      'subtree': true,
'attributeFilter': ['class']
    });
return mo;
}

function acmo(proc) {
    let mo = new MutationObserver((records) => {
proc();
});
    mo.observe(document.body, {
      'childList': true,
      'subtree': true
    });
return mo;
}

})();