Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

easy install #181

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
# 安装
## 自动(推荐)
0. 安裝[油猴](https://greasyfork.org/)插件
1. 点击油猴图标
2. 管理面板
3. 页面中点击实用工具
4. 在URL文本框输入源码[地址](https://raw.githubusercontent.com/eagleoflqj/p1a3_script/master/p1a3_script.js),点击导入
1. 点击

![安装過程](https://user-images.githubusercontent.com/14802181/85127126-730c9e00-b261-11ea-885c-6622b760352a.png)
https://raw.githubusercontent.com/eagleoflqj/p1a3_script/master/p1a3_script.user.js

## 手动(不推荐)
点击油猴图标->添加新脚本,粘贴p1a3_script.js的源码,Ctrl+S
Expand Down
4 changes: 3 additions & 1 deletion p1a3_script.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ==UserScript==
// @name 1p3a_script
// @namespace https://github.com/eagleoflqj/p1a3_script
// @version 0.10.2
// @version 0.10.3
// @description 方便使用一亩三分地
// @author Liumeo
// @match https://www.1point3acres.com/*
Expand All @@ -22,6 +22,8 @@
(function () {
'use strict';

alert('为了方便安装,本脚本将会停止维护,最新版本请访问 https://github.com/eagleoflqj/p1a3_script');

const jq = jQuery.noConflict();
// 为本地存储添加命名空间
const getValue = (namespace, name) => GM_getValue(namespace + '::' + name);
Expand Down
166 changes: 166 additions & 0 deletions p1a3_script.user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
// ==UserScript==
// @name 1p3a_script
// @namespace https://github.com/eagleoflqj/p1a3_script
// @version 0.10.4
// @description 方便使用一亩三分地
// @author Liumeo
// @match https://www.1point3acres.com/*
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_deleteValue
// @grant GM_addStyle
// @grant GM_registerMenuCommand
// @grant GM_getResourceText
// @grant GM_info
// @require https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js
// @require https://raw.githubusercontent.com/eagleoflqj/p1a3_script/master/QA.js
// @require https://raw.githubusercontent.com/eagleoflqj/p1a3_script/master/dream-ui.min.js
// @resource dreamui https://raw.githubusercontent.com/eagleoflqj/p1a3_script/master/dream-ui.css
// @resource setting https://raw.githubusercontent.com/eagleoflqj/p1a3_script/master/setting.html
// ==/UserScript==

(function () {
'use strict';

const jq = jQuery.noConflict();
// 为本地存储添加命名空间
const getValue = (namespace, name) => GM_getValue(namespace + '::' + name);
const setValue = (namespace, name, value) => GM_setValue(namespace + '::' + name, value);
const deleteValue = (namespace, name) => GM_deleteValue(namespace + '::' + name);
// 可隐藏的模块
const hideData = [
{ value: '#portal_block_76 > div', text: "水车排行" },
{ value: '#frameLXyXrm', text: "4x3" },
{ value: '#portal_block_421_content', text: "指尖新闻" },
{ value: '#portal_block_444_content', text: "生活攻略" },
{ value: '#portal_block_449_content', text: "疫情动态" },
{ value: '#portal_block_499_content', text: "绿卡排期" },
{ value: '#portal_block_424_content', text: "精品网课" },
];
const hideList = hideData.map(e => e.value); // 可隐藏的模块选择器列表
const hide = () => hideList.forEach(selector => jq(selector).css('display', getValue('hide', selector) ? 'none' : 'block')); // 按本地存储隐藏模块
// 添加设置对话框
GM_registerMenuCommand('设置', () => {
UI.dialog({
title: '设置',
content: GM_getResourceText('setting'),
maskClose: true,
showButton: false
});
// 隐藏模块
const settingHideData = JSON.parse(JSON.stringify(hideData)); // 深拷贝
settingHideData.forEach(e => getValue('hide', e.value) && (e.checked = true)); // 按本地存储打勾
UI.checkbox("#dui-hide", {
change: arg => { // 立即应用勾选
hideList.forEach(selector => arg.some(e => e === selector) ? setValue('hide', selector, true) : deleteValue('hide', selector));
hide();
},
data: settingHideData
});
});
GM_addStyle(GM_getResourceText('dreamui')); // 加载DreamUI样式
GM_addStyle('.ui-checkbox {margin-right:20px; margin-top:20px}'); // CSS优先级问题
hide();
// 针对不同页面的操作
const url = window.location.href;
if (url.search(/https:\/\/www\.1point3acres\.com\/bbs\/((forum|thread|tag|plugin.php\?id=dsu_paulsign:sign).*)?$/) == 0) { // 可签到、答题的页面
// 自动签到
const sign = jq('div.flex > a:contains("签到领奖")')[0];
sign && (sign.target = '_blank') && sign.click(); // 点击签到领奖
if (url === 'https://www.1point3acres.com/bbs/plugin.php?id=dsu_paulsign:sign&operation=qiandao&infloat=0&inajax=0') { // 签到成功跳转页
return;
}
// 签到后自动答题
const dayquestion = jq('#ahome_question')[0] || jq('a.text-xs:contains(答题中)')[0];
!sign && dayquestion && dayquestion.onclick && dayquestion.click();
// 新特性通知,不干扰签到、答题
!sign && !(dayquestion && dayquestion.onclick) && (() => {
const currentVersion = GM_info.script.version;
// 每个版本只通知一次
getValue('global', 'lastVersion') !== currentVersion && (setValue('global', 'lastVersion', currentVersion) || 1) &&
UI.notice.success({
title: currentVersion + '更新提示',
content: '更新自动答题selector',
autoClose: 8000
});
})();
}
if (url === 'https://www.1point3acres.com/next/daily-checkin') {
const panel = document.querySelector('.col-span-12');
setTimeout(() => {
panel.querySelector('.grid-cols-5 .rounded-md.border:last-child').click();
// setInterval(() => panel.querySelector('.text-center > button').click(), 1000);
}, 1000);
}
if (url === 'https://www.1point3acres.com/next/daily-question') { // 自动答题页
const helper = () => {
const form = document.querySelector('.col-span-12');
const questionElement = form.querySelector('.text-orange');
if (!questionElement) {
setTimeout(helper, 1000);
return
}
const question = questionElement.textContent.slice(4).trim();
const answer = QA[question];
if (!answer) { // 题库不含此题
const prompt = `尚未收录此题答案。如果您知道答案,请将\n"\n${question}\n{您的答案}\n"\n以issue形式提交至https://github.com/eagleoflqj/p1a3_script/issues`;
console.log(prompt);
return;
}
// 自动回答
const option_list = [];
const answer_list = typeof answer === 'string' ? [answer] : answer;
// 答案和选项取交集
form.querySelectorAll('.mt-4 > div')
.forEach(option => answer_list
.filter(answer => option.textContent.trim() === answer)
.forEach(() => option_list.push(option)));
if (!option_list.length) {
console.log(prompt);
return;
}
if (option_list.length > 1) {
alert('[Warning] 多个选项与题库答案匹配');
return;
}

option_list[0].click();
// setInterval(() => form.querySelector('.text-center > button').click(), 1000);
console.log(question + '\n答案为:' + answer);
}
helper();
}
if (url.search('thread') > 0) { // 详情页
// 自动查看学校、三维
const elements = jq('.typeoption a:contains(点击查看)');
elements.toArray().forEach(element => element.onclick());
} else if (url.search('forum-82-1') > 0 || url.search('forum.php\\?mod=forumdisplay&fid=82') > 0) { // 结果汇报列表页
// 按上次的筛选条件过滤录取结果
const search_ids = ['planyr', 'planterm', 'planmajor', 'plandegree', 'planfin', 'result', 'country']; // 过滤下拉菜单id
const search_button = jq('#searhsort > div.ptm.cl > button'); // 搜索按钮
if (GM_getValue('searchoption')) { // 上次过滤了
search_ids.forEach(id => jq('#' + id).val(GM_getValue(id)));// 自动填充下拉菜单
if (url.search('filter') < 0) { // 当前页面没有过滤
search_button.click(); // 自动过滤
return;
}
}
search_button.click(() => { // 如果不全是默认值,记下当前选项
search_ids.some(id => jq('#' + id).val() !== '0') && GM_setValue('searchoption', 1);
GM_getValue('searchoption') && search_ids.forEach(id => GM_setValue(id, jq('#' + id).val()));
});
// 添加重置按钮
const reset_button = jq('<button type="button" class="pn pnc"><em>重置</em></button>');
reset_button.click(() => { // 重置、清存储
GM_deleteValue('searchoption');
search_ids.forEach(id => {
jq('#' + id).val('0');
GM_deleteValue(id);
});
});
search_button.after(reset_button);
// 折叠占空间的提示
const img = jq('#forum_rules_82_img')[0];
img && img.src.search('collapsed_no') > 0 && img.onclick();
}
})();