Greasy Fork is available in English.

公众号图文编辑图片一键居中

2021/7/29 上午9:56:54

// ==UserScript==
// @name        公众号图文编辑图片一键居中
// @namespace   https://gitee.com/wang-yifan0905
// @match       https://mp.weixin.qq.com/cgi-bin/appmsg
// @grant       none
// @version     1.1
// @author      伍陆柒
// @description 2021/7/29 上午9:56:54
// ==/UserScript==

  "use strict"
  window.onload=function(){
  setTimeout(function(){
      var box = document.querySelector("#mpa-extra-tools-container");
      var divBtn = document.createElement('div');
      divBtn.innerHTML = "图片一键居中";
      divBtn.style.padding = "5px";
      divBtn.style.background = "#07c160";
      divBtn.style.color = "#ffffff";
      divBtn.style.fontSize = "12px";
      divBtn.style.cursor = "pointer"
      box.appendChild(divBtn);
        divBtn.addEventListener("click", function(){
        var parent = document.getElementById("ueditor_0").contentWindow.document.querySelector(".view");
        var imgArr = parent.getElementsByTagName("img");
        for(var i=0;i<imgArr.length;i++){
        imgArr[i].parentNode.style.display = "block";
        imgArr[i].parentNode.style.textAlign = "center";
   }
 })
  },2000)

 
 }