Predecision Label

Decision label. Try to take over the world!

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