Predecision Label

Decision label. Try to take over the world!

目前为 2024-10-16 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Predecision Label
  3. // @namespace http://baidu.com/
  4. // @version 0.4.3
  5. // @description Decision label. Try to take over the world!
  6. // @author You
  7. // @match http://ov.baidu-int.com/*
  8. // @match http://yf.baidu-int.com/*
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=baidu-int.com
  10. // @grant none
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16. let label_list = [];
  17. let cur_label = {};
  18. let ads_id = -1;
  19. let start_pre_seq = -1;
  20. let end_pre_seq = -1;
  21. let cur_pre_seq = -1;
  22. let cur_obs_id = -1
  23. let is_label_panel_show = false;
  24. let old_info;
  25. var initialMouseX, initialMouseY, initialElementX, initialElementY;
  26.  
  27. function set_cur_info() {
  28. var _ads_id = parseInt($("section").children('p').children('span')[1].textContent);
  29. var _cur_pre_seq = parseInt($(".seq-wrap").text().replace('PlanSeq:', ""));
  30. var _cur_obs_id = parseInt($("div.viz-detail-text-wrapper > span").text().replace('id:', ""));
  31. if (window.location.host == 'yf.baidu-int.com') {
  32. _ads_id = getUrlParam("ads_id");
  33. if (_ads_id != null) {
  34. _ads_id = parseInt(_ads_id);
  35. } else {
  36. _ads_id = -1;
  37. }
  38. var s = $('#dreamview-container > div > div > div.pannel.react-draggable > div.context > div.dashboard.inner-box.scrollHeightL > table > tbody > tr:nth-child(3) > td:nth-child(2) > p:nth-child(3) > span')[0];
  39. _cur_pre_seq = parseInt(s.textContent.replace('PRE:', ""));
  40. }
  41. ads_id = isNaN(_ads_id)? ads_id: _ads_id;
  42. cur_pre_seq = isNaN(_cur_pre_seq)? cur_pre_seq: _cur_pre_seq;
  43. cur_obs_id = isNaN(_cur_obs_id)? cur_obs_id: _cur_obs_id;
  44. $('#ads_id').text(ads_id);
  45. $('#seq_num').text(cur_pre_seq);
  46. $('#obs_id').text(cur_obs_id);
  47. cur_label.ads_id = ads_id;
  48. console.log(ads_id);
  49. console.log(cur_pre_seq);
  50. console.log(cur_obs_id);
  51. }
  52.  
  53. function getUrlParam(name)
  54. {
  55. var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
  56. var value = window.location.search.substr(1).match(reg);
  57. if (value != null) return unescape(value[2]); return null;
  58. }
  59.  
  60. function setStartSeq() {
  61. set_cur_info();
  62. cur_label.start_seq = cur_pre_seq;
  63. console.log("set start seq", cur_label.start_seq);
  64. }
  65. function setEndSeq() {
  66. set_cur_info();
  67. cur_label.end_seq = cur_pre_seq;
  68. console.log("set end seq", cur_label.end_seq);
  69. }
  70.  
  71. function addLabelToShow(label) {
  72. if (label == undefined) {
  73. return;
  74. }
  75. var str = "upload_times(" + label.ads_id + ',' + label.obs_id + ',' + label.start_seq + ',' + label.end_seq + ',' + label.dec_label + ')\n';
  76. $('#decision_label_show_list').append(str);
  77. console.log("add show string", str);
  78. }
  79.  
  80. function onLabel(dec_label){
  81. $('#label_btn_' + dec_label.toString()).click(function() {
  82. // 添加类以实现按钮变亮效果
  83. $('#label_btn_' + dec_label.toString()).addClass('clicked');
  84.  
  85. // 在 300 毫秒后移除类以恢复按钮原始状态
  86. setTimeout(function() {
  87. $('#label_btn_' + dec_label.toString()).removeClass('clicked');
  88. }, 300);
  89. });
  90. if (isNaN(ads_id) || isNaN(cur_obs_id) || isNaN(cur_label.start_seq) || isNaN(cur_label.end_seq) || isNaN(dec_label)) {
  91. return;
  92. }
  93. cur_label.ads_id = ads_id;
  94. cur_label.obs_id = cur_obs_id;
  95. cur_label.dec_label = dec_label;
  96. console.log('add decision label to list', cur_label);
  97. label_list.push(cur_label);
  98. addLabelToShow(cur_label);
  99. cur_label = {};
  100. }
  101.  
  102. function showDecisionLabelPanel() {
  103. $("#decision_label_panel").css('z-index', -1 * $("#decision_label_panel").css('z-index'));
  104. console.log("move decision label panel to z index ", $("#decision_label_panel").css('z-index'));
  105. }
  106. // Your code here...
  107. var label_tab = `
  108. <button type="button" onclick="showDecisionLabelPanel()" class="ant-btn ant-btn-default ant-btn-sm" style="margin-right: 10px;">
  109. <div class="ant-space ant-space-horizontal ant-space-align-center" style="gap: 8px;">
  110. <div class="ant-space-item">
  111. 决策标注
  112. </div>
  113. </div>
  114. </button>
  115. `;
  116.  
  117. var label_panel_html =`
  118. <div class="container-fluid" id="decision_label_panel" style="position: absolute; top: 55%; left: 74%;width: 23%;height:30%;background-color: #292f42;z-index: -9999;">
  119. <div class="col-md-2 column" style="float: center;">
  120. </div>
  121. <div class="row clearfix">
  122. <div class="col-md-2 column" style="float: center;">
  123. <div class="row clearfix">
  124. <label>
  125. ads_id:
  126. </label>
  127. <label id='ads_id'>
  128. -1
  129. </label>
  130. <label>
  131. obs_id:
  132. </label>
  133. <label id='obs_id'>
  134. -1
  135. </label>
  136. <label>
  137. seq_num:
  138. </label>
  139. <label id='seq_num'>
  140. -1
  141. </label>
  142. </div>
  143. </div>
  144. <div class="col-md-2 column">
  145. <div class="row clearfix" style="float: center;">
  146. <button style="width:45%;margin-left: 3%;background-color: red;transition: background-color 0.3s ease;" onclick="setStartSeq()">
  147. seq_start
  148. </button>
  149. <button style="width:45%;margin-left: 2%;background-color: green;" onclick="setEndSeq()">
  150. seq_end
  151. </button>
  152. </div>
  153. <br>
  154. <div class="btn-group" style="margin-left: 2%">
  155. <button style="background-color: #FFBBFF;margin-left: 5px;margin-top: 5px;" id="label_btn_0" type="button" value="0" onclick="onLabel(0)">
  156. Ignore
  157. </button>
  158. <button style="background-color: #00DDDD;margin-left: 5px;margin-top: 5px;" id="label_btn_1" type="button" value="1" onclick="onLabel(1)">
  159. Follow
  160. </button>
  161. <button style="background-color: #8C0044;margin-left: 5px;margin-top: 5px;" id="label_btn_2" type="button" value="2" onclick="onLabel(5)">
  162. Yield
  163. </button>
  164. <button style="background-color: #886600;margin-left: 5px;margin-top: 5px;" id="label_btn_3" type="button" value="3" onclick="onLabel(2)">
  165. Overtake
  166. </button>
  167. <button style="background-color: #008844;margin-left: 5px;margin-top: 5px;" id="label_btn_4" type="button" value="4" onclick="onLabel(4)">
  168. NudgeYield
  169. </button>
  170. <button style="background-color: #008888;margin-left: 5px;margin-top: 5px;" id="label_btn_5" type="button" value="5" onclick="onLabel(5)">
  171. NudgeOvetake
  172. </button>
  173. <button style="background-color: #0000CD;margin-left: 5px;margin-top: 5px;" id="label_btn_6" type="button" value="6" onclick="onLabel(6)">
  174. NudgeIgnore
  175. </button>
  176. </div>
  177. <br>
  178. <div>
  179. <textarea id="decision_label_show_list" placeholder="" rows="6" style="width:100%;background-color: #292f42;padding: 10px;max-width: 100%;max-height: 100%;line-height: 1.5;border-radius: 5px;border: 1px solid #ccc;"></textarea>
  180. <button style="background-color: #808000;margin-top: 5px;width:100%" type="button" onclick="clearLabel()">
  181. Clear
  182. </button>
  183. </div>
  184. </div>
  185. </div>
  186. </div>
  187. </div>
  188.  
  189. `;
  190. function clearLabel() {
  191. $('#decision_label_show_list').val('');
  192. label_list = [];
  193. }
  194.  
  195.  
  196. function onMouseMove(event) {
  197. // 计算鼠标偏移量
  198. var offsetX = event.clientX - initialMouseX;
  199. var offsetY = event.clientY - initialMouseY;
  200.  
  201. // 将偏移量应用于元素的位置
  202. $('#decision_label_panel').css({
  203. left: initialElementX + offsetX + 'px',
  204. top: initialElementY + offsetY + 'px'
  205. });
  206. }
  207.  
  208. // 鼠标释放事件处理程序
  209. function onMouseUp() {
  210. // 移除事件监听器
  211. $(document).off('mousemove', onMouseMove);
  212. $(document).off('mouseup', onMouseUp);
  213. }
  214.  
  215. window.onMouseMove = onMouseMove;
  216. window.onMouseUp = onMouseUp
  217. window.set_cur_info = set_cur_info;
  218. window.showDecisionLabelPanel = showDecisionLabelPanel;
  219. window.setStartSeq = setStartSeq;
  220. window.setEndSeq = setEndSeq;
  221. window.onLabel = onLabel;
  222. window.clearLabel = clearLabel;
  223.  
  224. setTimeout(function() {
  225. console.log("3s time out");
  226. $(".ov-header-operations").prepend(label_tab);
  227. $("body").append(label_panel_html);
  228. $('#decision_label_panel').mousedown(function(event) {
  229. var elementTop = $('#decision_label_panel').offset().top;
  230. var mouseY = event.clientY;
  231. console.log('elementTop', elementTop, 'mouseY', mouseY);
  232. if (mouseY > elementTop + 10) {
  233. return; // 如果不在顶部,则忽略拖动
  234. }
  235. // 记录鼠标位置和元素初始位置
  236. initialMouseX = event.clientX;
  237. initialMouseY = event.clientY;
  238. initialElementX = $('#decision_label_panel').offset().left;
  239. initialElementY = $('#decision_label_panel').offset().top;
  240. console.log("initialMouseX", initialMouseX);
  241.  
  242. // 添加事件监听器
  243. $(document).mousemove(onMouseMove);
  244. $(document).mouseup(onMouseUp);
  245. });
  246. }, 3000); // 等待3秒
  247.  
  248. })();