Greasy Fork

来自缓存

Greasy Fork is available in English.

PPT预览自动切换

zh-CN PPT预览自动切换,触发鼠标点击事件,自动翻页

当前为 2021-08-27 提交的版本,查看 最新版本

// ==UserScript==
// @name         PPT预览自动切换
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description: PPT预览自动切换,触发鼠标点击事件,自动翻页
// @author       黄种鑫
// @match        *://*.officeapps.live.com/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// @description zh-CN PPT预览自动切换,触发鼠标点击事件,自动翻页
// ==/UserScript==

(function () {
  'use strict';
  function init() {
    var curPage = +(document.querySelector('#SlideLabel-Medium14').innerText.match(/\d+/)[0] || 1)
    for (var i = 0; i < 1000 * curPage; i++) {
      document.dispatchEvent(new KeyboardEvent('keydown', { keyCode: 33 }))
    }
  }

  function click() {
    document.querySelector('#SlidePanel').click()
  }

  window.addEventListener('message', (e) => {
    if (location.ancestorOrigins.length === 1) {
      // 母页面处理
      if (e.origin.includes('officeapps.live.com')) { // 子页面传过来的消息,转发到外部去
        console.log('message forward to parent page')
        top.postMessage(e.data, '*')
      } else { // 外部来的消息,转发到子页面去
        console.log('message forward to child page')
        document.querySelector('#wacframe').contentWindow.postMessage(e.data, '*')
      }
    } else {
      // 子页面处理
      if (e.data === 'init') {
        init()
      } else if (e.data === 'click') {
        click()
      }
    }
  })

  var timer = setInterval(() => {
    if (document.querySelector('#SlidePanel #scc')) {
      clearInterval(timer)
      console.log('ppt loaded')
      top.postMessage({
        eventName: 'loaded'
      }, '*')
    }
  }, 10)
})();