// ==UserScript==
// @name scifinder2.3.2
// @namespace https://origin-scifinder.cas.org
// @version 2.3.2
// @description 从scifinder和scifinder-n中获取所需要的化学信息
// @author zhaomeng
// @match https://*/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net
// @grant unsafeWindow
// @grant GM_getResourceText
// @grant GM_addStyle
// @resource customCSS https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css
// @require https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js
// @require https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js
// @require https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js
// @license MIT
// @downloadURL none
// ==/UserScript==
(function() {
'use strict';
/*将以下的js脚本注入浏览器页面,实现页面元素点选,获取页面的css*/
/* globals jQuery, $, waitForKeyElements */
var css =GM_getResourceText("customCSS");
GM_addStyle(css);
/*创建页面的按钮*/
var modal = '
'
$("body").append(modal)
$('body').append('
')
var loginkey = localStorage.getItem("loginkey");
console.log('11111111111111111')
console.log(loginkey)
if(loginkey!=null){
$('#draggable').html('')
}else{
/*登陆模态框*/
$('#kj_login').on("click",function(event){
/*登陆组件*/
var login = ''
var login_button = ''
$("div.modal-body").html(login)
$("div.modal-footer").html(login_button)
$('#myModal').modal("show")
})
}
// 点击登陆按钮,发送 AJAX 请求进行登陆操作
$(document).on('click', '#loginBtn', function() {
var username = $("#username").val();
var password = $("#password").val();
/*$('#draggable').html('')*/
$("#loginMsg").html("登陆成功。");
$('#myModal').modal("hide")
$.ajax({
type: "POST",
url: "http://127.0.0.1:8000/login/access-token",
contentType: "application/json",
data: JSON.stringify({
username: username,
password: password
}),
success: function(result){
// 登陆成功:刷新页面或者跳转到其他页面
console.log(result.token)
var loginkey = localStorage.setItem("loginkey",result.token);
console.log(result.token)
$("#loginMsg").html("登陆成功。");
location.reload()
/*$('body').append('
')
*/
},
error: function(result){
console.log(result)
localStorage.removeItem('loginkey')
alert('登陆失败,请检查您输入的用户名和密码是否正确。')
// 登陆失败:提示错误信息
$("#loginMsg").html("登陆失败,请检查您输入的用户名和密码是否正确。");
}
});
})
//获取需要拖动的元素
var draggableElement = document.getElementById("draggable");
//记录拖动状态的变量
var isDragging = false;
//记录鼠标位置和元素位置的变量
var currentX;
var currentY;
var initialX;
var initialY;
var xOffset = 0;
var yOffset = 0;
//添加鼠标按下事件监听器
draggableElement.addEventListener("mousedown", dragStart);
//添加鼠标移动事件监听器
draggableElement.addEventListener("mousemove", drag);
//添加鼠标释放事件监听器
draggableElement.addEventListener("mouseup", dragEnd);
//添加鼠标离开事件监听器
draggableElement.addEventListener("mouseleave", dragEnd);
//鼠标按下时触发
function dragStart(e) {
initialX = e.clientX - xOffset;
initialY = e.clientY - yOffset;
if (e.target === draggableElement) {
isDragging = true;
}
}
//鼠标移动时触发
function drag(e) {
if (isDragging) {
e.preventDefault();
currentX = e.clientX - initialX;
currentY = e.clientY - initialY;
xOffset = currentX;
yOffset = currentY;
setTranslate(currentX, currentY, draggableElement);
}
}
//鼠标释放时触发
function dragEnd(e) {
initialX = currentX;
initialY = currentY;
isDragging = false;
}
//设置元素位置的函数
function setTranslate(xPos, yPos, el) {
el.style.transform = "translate3d(" + xPos + "px, " + yPos + "px, 0)";
}
/*存储页面获取到的数据*/
var data={}
/*获取文献信息*/
$(document).on('click', '#kj_selected', function() {
$("div.modal-body").html('')
var list=[]
$('.substanceRN>a:nth-child(1)').each(function(){
var cas = $(this).text()
list.push(cas)
})
var list1=[]
$('ol.citation li a:nth-child(1)').each(function(){
var citiation = $(this).text()
list1.push(citiation)
})
var doi = $('li.breadcrumb:nth-child(1)>span.label').text()
var item={
casno:list,
citiations:list1,
doi:doi
}
console.log(item)
if(item.casno && item.citiations&& item.doi){
console.log(item)
var ff = '- DOI:
- '+item.doi+'
- CASNO:
- '+list.join("
")+' - Citiations:
- '+list1.join("
")+'
'
$("div.modal-body").html(ff)
$("div.modal-footer").html('')
$('#myModal').modal("show")
/*------------------*/
data=item
}else{
alert("确认是否为文献页面!")
}
})
/*scifinder-n基本信息*/
$(document).on('click', '#kj_selected1', function() {
$("div.modal-body").html('')
var list=[]
$('ul.list-unstyled.list-striped li span').each(function(){
var name = $(this).text()
list.push(name)
})
var enname = $('.substance-name.ng-star-inserted').text()
var result_cas = $('span>mark').text().trim()
var casno = $('title').text()
var item={
casno:casno,
ename: enname,
result_cas:result_cas,
enbm:list,
}
console.log(item)
if(item.casno && item.result_cas && item.ename){
console.log(item)
var ff = '- 搜索CasNo:
- '+item.casno+'
- 英文名:
- '+item.ename+'
- 结果CasNo:
- '+item.result_cas+'
- 别名:
- '+list.join("
")+'
'
$("div.modal-body").html(ff)
$("div.modal-footer").html('')
$('#myModal').modal("show")
data=item
}else{
alert("确认是否为基本信息页面!")
}
})
/*合成路线及文献*/
$(document).on('click', '#kj_selected2', function() {
$("div.modal-body").html('')
$('.dropdown-menu').remove()
var list=[]
var casno =$(".toolbar-title span[class]:last-child").text()
$('sf-reaction-result-page .reaction-result-answers').each(function(index){
var authors = $("span.authors-text",this).text().trim()
var title = $('h4>a',this).text().trim()
var breif=$(".bibliography",this).text().trim()
var cas_start=[]
$('.reaction-tile-reactant .rn-no-image.ng-star-inserted',this).each(function(){
cas_start.push($(this).text().trim())
})
$('.reaction-tile-reactant img',this).each(function(){
var cas = $(this).attr("alt").trim()
cas_start.push(cas)
})
var cas_end=[]
$('.reaction-tile-product .rn-no-image.ng-star-inserted',this).each(function(){
cas_end.push($(this).text().trim())
})
$('.reaction-tile-product img',this).each(function(){
var cas = $(this).attr("alt")
cas_end.push(cas)
})
var relate=[]
$('.summary-steps.ng-star-inserted div.summary-step.ng-star-inserted',this).each(function(){
$('div.summary-stage.ng-star-inserted',this).each(function(){
var step=$(this).text().trim()
relate.push(step)
})
})
var rate = $('.yield-value',this).text()
var item={title:title,authors:authors,breif:breif,cas_start:cas_start,cas_end:cas_end,relate:relate,rate:rate,casno:casno}
list.push(item)
})
if(list.length>0){
console.log(list)
var content=''
for(var j=0;j'+list[j].title+'作者:'+list[j].authors+'简介:'+list[j].breif+'合成路线:'+list[j].cas_start.join("+")+'->'+list[j].cas_end.join("+")+'产率:'+list[j].rate+'实验步骤:'+list[j].relate.join('
').trim()+'
'
content+=ff
}
$("div.modal-body").html('CasNo:'+list[0].casno+'
'+content)
$("div.modal-footer").html('')
$('#myModal').modal("show")
data={"casno":list[0].casno,"compose":list}
}else{
alert("确认是否为合成路线页面!")
}
})
/*基本信息*/
$(document).on('click', '#refer', function() {
$.ajax({
headers: {
"token": loginkey
},
type: "POST",
url: "http://127.0.0.1:8000/references/",
contentType: "application/json",
data: data,
success: function(result){
// 登陆成功:刷新页面或者跳转到其他页面
//location.reload();
$("#loginMsg").html("发送成功。");
},
error: function(){
localStorage.removeItem('loginkey')
alert('发送失败。')
// 登陆失败:提示错误信息
$("#loginMsg").html("发送失败");
}
});
});
/*接口结束*/
/*基本信息*/
$(document).on('click', '#baseinfo', function() {
$.ajax({
headers: {
"token": loginkey
},
type: "POST",
url: "http://127.0.0.1:8000/info/",
contentType: "application/json",
data: data,
success: function(result){
// 登陆成功:刷新页面或者跳转到其他页面
//location.reload();
$("#loginMsg").html("发送成功。");
},
error: function(){
localStorage.removeItem('loginkey')
alert('发送失败。')
// 登陆失败:提示错误信息
$("#loginMsg").html("发送失败");
}
});
});
/*接口结束*/
/*基本信息*/
$(document).on('click', '#compose', function() {
$.ajax({
headers: {
"token": loginkey
},
type: "POST",
url: "http://127.0.0.1:8000/composes/",
contentType: "application/json",
data: data,
success: function(result){
// 登陆成功:刷新页面或者跳转到其他页面
//location.reload();
$("#loginMsg").html("发送成功。");
},
error: function(){
localStorage.removeItem('loginkey')
alert('发送失败。')
// 登陆失败:提示错误信息
$("#loginMsg").html("发送失败");
}
});
});
/*接口结束*/
// Your code here...
})();