Greasy Fork is available in English.

ListProjects - gitcode.net

2023/11/17 14:57:11

Fra 17.11.2023. Se den seneste versjonen.

  1. // ==UserScript==
  2. // @name ListProjects - gitcode.net
  3. // @namespace Violentmonkey Scripts
  4. // @match https://gitcode.net/users/u011405698/projects
  5. // @grant none
  6. // @version 2311171546
  7. // @author alvin
  8. // @license MIT
  9. // @description 2023/11/17 14:57:11
  10. // ==/UserScript==
  11.  
  12. function data_to_csv(data, name) {
  13. const blob = new Blob(data, { type: 'text/csv,charset=UTF-8' });
  14. const uri = URL.createObjectURL(blob);
  15. let downloadLink = document.createElement('a');
  16. downloadLink.href = uri;
  17. downloadLink.download = (name + ".csv") || "temp.csv";
  18. document.body.appendChild(downloadLink);
  19. downloadLink.click();
  20. document.body.removeChild(downloadLink);
  21. }
  22.  
  23. function exportProjects(){
  24. projects = document.querySelectorAll("li.project-row")
  25. //保存数据,注意换行格式
  26. var data_list = Array();
  27. data_list.push(["标题", "链接", "\n"]);
  28. projects.forEach(project => {
  29. href = project.querySelector('.project').href
  30. description = ''
  31. descriptionNode = project.querySelector('.description')
  32. if (descriptionNode) {
  33. description = descriptionNode.innerHTML
  34. }
  35. data_list.push([href, description]);
  36. console.log(href)
  37. console.log(description)
  38.  
  39. })
  40. data_to_csv(data_list, "projects.csv");
  41. }
  42.  
  43.  
  44. function addbut() {
  45. 'use strict';
  46. console.log('我的脚本加载了');
  47. var button = document.createElement("button"); //创建一个input对象(提示框按钮)
  48. button.id = "id001";
  49. button.textContent = "导出项目列表";
  50. button.style.width = "60px";
  51. button.style.height = "40px";
  52. button.style.align = "center";
  53.  
  54. //绑定按键点击功能
  55. button.onclick = function () {
  56. console.log('点击了按键');
  57. exportProjects();
  58. //为所欲为 功能实现处
  59. //alert("你好");
  60. return;
  61. };
  62.  
  63. var x = document.querySelector('.gl-pagination');
  64. //在浏览器控制台可以查看所有函数,ctrl+shift+I 调出控制台,在Console窗口进行实验测试
  65. x.appendChild(button);
  66.  
  67. //var y = document.getElementById('s_btn_wr');
  68. //y.appendChild(button);
  69. };
  70.  
  71.  
  72. window.onload = function () {
  73. addbut();
  74. }
  75.