Jianshu MD AUTO Scroll

jianshu Markdown preview AUTO scroll

目前为 2016-11-15 提交的版本。查看 最新版本

// ==UserScript==
// @name         Jianshu MD AUTO Scroll
// @name:zh-CN   简书 Markdown 预览同步滚动
// @namespace    jianshu
// @include 	 *://www.jianshu.com/writer*
// @version      1.0.1
// @description  jianshu Markdown preview AUTO scroll
// @description:zh-CN  使简书的在线 Markdown 编辑器具有输入和预览同步滚动的功能
// @author       BlindingDark
// @grant        none
// ==/UserScript==
//
(function() {
    'use strict';
    // Your code here...
    //text mousetrap span6 preview
    function jQuery_start(){

	var txtMain;
	var spPreview;

	function tampermonkey_start(){

	    txtMain = $('.text.mousetrap')[0];
	    spPreview = $('.span6.preview')[0];

	    txtMain.onscroll=function(){ 
		spPreview.scrollTop = Math.round((txtMain.scrollTop + txtMain.clientHeight) * spPreview.scrollHeight / txtMain.scrollHeight - spPreview.clientHeight);
	    };

	    spPreview.onscroll=function(){
		txtMain.scrollTop = Math.round((spPreview.scrollTop + spPreview.clientHeight) * txtMain.scrollHeight  / spPreview.scrollHeight - txtMain.clientHeight);
	    };

	}



	function tampermonkey_wait(){

	    if ((txtMain = $('.text.mousetrap')[0])===undefined)	{    
		window.setTimeout(tampermonkey_wait,1000); 
	    } else {
		if ((spPreview = $('.span6.preview')[0])===undefined){
		    window.setTimeout(tampermonkey_wait,1000); 
		} else {
		    tampermonkey_start();
		}
	    }
	}


	tampermonkey_wait();

	//TODO 点击预览按钮重新设置监听


    }


    function Tampermonkey_jQuery_wait(){
	if(typeof jQuery == 'undefined') {
	    window.setTimeout(Tampermonkey_jQuery_wait,1000);
	    console.log("waiting for jQuery prepared");
	}
	else {
	    $ = jQuery;
	    console.log("jQuery ready");

	    jQuery_start();
	}

    }
    Tampermonkey_jQuery_wait();




})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址