WordPress.com edit post redirects

Redirects the new post page to the classic post page

目前为 2015-03-19 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name WordPress.com edit post redirects
  3. // @namespace tpenguinltg
  4. // @description Redirects the new post page to the classic post page
  5. // @include https://wordpress.com/post*
  6. // @include https://wordpress.com/page*
  7. // @version 1.2.1
  8. // @homepageURL https://greasyfork.org/en/scripts/8581-wordpress-com-edit-post-redirects
  9. // @homepageURL https://github.com/tpenguinltg/wpcom-edit-post-redirect.user.js
  10. // @grant none
  11. // @license MPLv2.0; http://mozilla.org/MPL/2.0/
  12. // @copyright 2015, tPenguinLTG (http://tpenguinltg.wordpress.com/)
  13. // @run-at document-start
  14. // ==/UserScript==
  15.  
  16. // Function by dystroy. From http://stackoverflow.com/a/14388512
  17. function fetchJSONFile(path, callback) {
  18. var httpRequest = new XMLHttpRequest();
  19. httpRequest.onreadystatechange = function() {
  20. if (httpRequest.readyState === 4) {
  21. if (httpRequest.status === 200) {
  22. var data = JSON.parse(httpRequest.responseText);
  23. if (callback) callback(data);
  24. }//end if
  25. }//end if
  26. };//end onreadystatechange()
  27. httpRequest.open('GET', path);
  28. httpRequest.send();
  29. }
  30.  
  31. // gather information from URL
  32. var parsedUrl=window.location.pathname.match(/(post|page)(\/(\d+)\/(\d+|new))?/);
  33. var postType=parsedUrl[1];
  34. var blogid=parsedUrl[3];
  35. var postid=parsedUrl[4];
  36.  
  37. // if no blog given
  38. if(!blogid) {
  39. // scrape the edit URL from the page when the DOM has finished loading
  40. window.onload=function() {
  41. window.location.replace(document.getElementsByClassName("switch-to-classic")[0].children[0].href);
  42. }; //end document.onload
  43. }// if
  44. else {
  45. // Redirect to post URL based on API results
  46. // API docs: https://developer.wordpress.com/docs/api/
  47. fetchJSONFile("https://public-api.wordpress.com/rest/v1.1/sites/"+blogid, function(data) {
  48. var postURL;
  49.  
  50. if(postid == "new") {
  51. postURL=data.URL+"/wp-admin/post-new.php?post_type="+postType;
  52. }//if
  53. else {
  54. postURL=data.URL+"/wp-admin/post.php?post="+postid+"&action=edit";
  55. }//end if
  56.  
  57. window.location.replace(postURL);
  58.  
  59. });
  60. }