Google的一个插件,针对Dynamics Crm 365 9.1版本的工具,查看字段名称等功能
新增文件夹:llqCrmHelper
新建一个manifest.json文件

{
"name": "llqCrmHelper", //设置插件名
"manifest_version": 2, //版本,这个是固定的
"version": "1.1.1", //插件版本,用于迭代识别
"description": "author:cwg 溜溜球CRM助手 2022-04-23 博客地址:https://www.cnblogs.com/parkerchen/", //插件描述
"icons": { //设置插件图标不同大小对应的图片
"16": "img/icon.png",
"48": "img/icon.png",
"128": "img/icon.png"
},
"browser_action": { //我个人理解为插件显示在菜单栏时候的行为,设置标题内容页等
"default_title": "llqCrmHelper",
"default_icon": {
"16": "img/icon.png"
},
"default_popup": "popup.html"
},
"permissions": [ //权限开通
"tabs",
"contextMenus",
"management",
"notifications",
"*://*/*",
"http://*/*",
"https://*/*"
],
"web_accessible_resources": [ "js/showFilderName.js", "js/showEntityMsgs.js" ]
}
新建一个popup.html文件

DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>llqCrmHelpertitle>
<style>
body {
width: 220px;
min-height: 300px;
}
style>
head>
<body>
<h2>溜溜球CRM助手h2>
<div style="margin-left: 20px; ">
<table style="line-height:25px;">
<tr>
<td>*td>
<td><a style="text-decoration-line: none; font-size: 16px; color: #1a73e8; " href="#" id="showFilderNameA">查看界面字段a>td>
tr>
<tr>
<td>*td>
<td><a style="text-decoration-line: none; font-size: 16px; color: #1a73e8; " href="#" id="showEntityMsgsA">查看实体信息a>td>
tr>
table>
div>
<script type="text/javascript" src="js/popup.js">script>
body>
html>
新增文件夹img,里面放icon.png
新增文件夹js,里面新增popup.js

//增加点击事件 let showFilderNameA = document.getElementById("showFilderNameA"); showFilderNameA.addEventListener("click", () => { showFilderName(); }); let showEntityMsgsA = document.getElementById("showEntityMsgsA"); showEntityMsgsA.addEventListener("click", () => { showEntityMsgs(); }); //显示字段名称的函数 function showFilderName() { //chrome.tabs 使用api和浏览器选项卡进行交互 chrome.tabs.getSelected(null, (tab) => { //传进来的参数是当前标签页 let title = tab.title; chrome.tabs.executeScript(null, { code: //"let ipt = document.getElementById('kw'); ipt.value = '小天才'; let btn = document.getElementById('su'); btn.click() ", //这种方法在页面上注入脚本后,可访问页面上的变量 " var th = document.getElementsByTagName('body')[0]; \n" + " var s = document.createElement('script'); \n" + " s.setAttribute('type', 'text/javascript'); \n" + " s.setAttribute('src', chrome.extension.getURL('js/showFilderName.js')); \n" + " th.appendChild(s); \n" + " " + " " + " ", }); }); } //显示实体信息 function showEntityMsgs() { chrome.tabs.getSelected(null, (tab) => { chrome.tabs.executeScript(null, { code: //这种方法在页面上注入脚本后,可访问页面上的变量 " var th = document.getElementsByTagName('body')[0]; \n" + " var s = document.createElement('script'); \n" + " s.setAttribute('type', 'text/javascript'); \n" + " s.setAttribute('src', chrome.extension.getURL('js/showEntityMsgs.js')); \n" + " th.appendChild(s); \n" + " " + " " + " ", }); }); }
文件夹js,里面新增showEntityMsgs.js

showEntityMsgAction(); //显示实体信息 function showEntityMsgAction() { var entityName = Xrm.Page.data.entity.getEntityName(); var entityid = Xrm.Page.data.entity.getId(); var msgs = "" + entityName + " \n"; msgs += "" + entityid + " \n"; Xrm.Utility.alertDialog(msgs); }
文件夹js,里面新增showFilderName.js

var headerbtn = document.getElementById("headerFieldsExpandButton"); //Head的下拉按钮 if (headerbtn) { headerbtn.click(); setTimeout(function () { showFilerNameAction(); }, 200); //延迟目的:让下拉的数据先出现 } else { showFilerNameAction(); } //显示字段名称 function showFilerNameAction() { var fieldArray = document.getElementsByTagName('label'); for (var i = 0; i < fieldArray.length; i++) { var field = fieldArray[i]; if (field.hasAttribute('id') && !field.hasAttribute('helperHanddled')//未被助手处理过的标签 && field.attributes['id'].value.indexOf('-field-label') > -1 ) { var fieldId = field.attributes['id'].value; var fileName_show = getFileNameByID(fieldId); field.insertAdjacentHTML('afterend', '' + fileName_show + '') field.parentNode.onclick = function (e) { var labelControl = this.querySelector('label'); var id = labelControl.attributes['id'].value; //拆分,获取字段名 var fileName = getFileNameByID(id); setTips(labelControl.innerText + ' ' + fileName + fieldTips(fileName)); } //标记为已处理,下次不再处理 field.setAttribute('helperHanddled', 1) } } } //通过标签ID获取字段名称,如果不符合规则,返回原值 //id-eb2fc372-18b6-4ea2-aeed-edb2fef91dd5-18-scc_subdivideddomain-field-label function getFileNameByID(id) { var fileName = id; fileName = id.replace("-field-label", ""); var index = fileName.lastIndexOf('-') + 1; if (fileName.length > index) { fileName = fileName.substr(index); } return fileName; } ///不同类型的字段显示相应的帮助信息 function fieldTips(fieldname) { try { console.log(location.href); var returnTips = ''; var attr = Xrm.Page.getAttribute(fieldname.replace('header_process_', '').replace('header_', ''));//兼容header字段 if (!attr) { return returnTips; } var controlType = attr.getAttributeType(); //lookup 显示相应的id typename 等 if (controlType == 'lookup') { var lookup = attr.getValue(); debugger; var id = lookup[0].id; var name = lookup[0].name; var entityName = (lookup[0].typename || lookup[0].entityType); returnTips += '
id: ' + id; returnTips += '
name: ' + name; returnTips += '
entityname: ' + entityName; } //picklist 显示每一个的值和标签 else if (controlType == 'optionset') { var opts = attr.getOptions(); for (var i = 0; i < opts.length; i++) { if (opts[i].value == 'null' && opts[i].value == '-1') { //这里是字符串null break; } returnTips += "
" + opts[i].value + ' ' + opts[i].text; } } return returnTips; } catch (e) { return ''; } } function removeTips() { var divTips = document.getElementById('divTips'); if (divTips != null) { document.body.removeChild(divTips); } } function setTips(tip) { var divTips = document.getElementById('divTips'); var closeTipsHtml = '[关闭]'; if (divTips == null) { var child = document.createElement('div'); child.id = 'divTips'; child.style.right = '5px'; child.style.bottom = '5px'; child.style.padding = '0px 15px 5px 15px'; child.style.position = 'absolute'; child.style.backgroundColor = '#216ab7'; child.innerHTML = closeTipsHtml + '' + tip + '
'; child.style.zIndex = 100; document.body.insertBefore(child, document.body.firstChild); } else { divTips.innerHTML = closeTipsHtml + '
' + tip + '
'; } }
代码编写完成,我们看一下效果