WordPress.com edit post redirects

Redirects the new post page to the classic post page

目前為 2015-03-16 提交的版本,檢視 最新版本

  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.1.0
  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. var parsedUrl=window.location.pathname.match(/(post|page)\/(\d+)\/(\d+|new)/);
  17. var postType=parsedUrl[1];
  18. var blogid=parsedUrl[2];
  19. var postid=parsedUrl[3];
  20.  
  21. // Function by dystroy. From http://stackoverflow.com/a/14388512
  22. function fetchJSONFile(path, callback) {
  23. var httpRequest = new XMLHttpRequest();
  24. httpRequest.onreadystatechange = function() {
  25. if (httpRequest.readyState === 4) {
  26. if (httpRequest.status === 200) {
  27. var data = JSON.parse(httpRequest.responseText);
  28. if (callback) callback(data);
  29. }//end if
  30. }//end if
  31. };//end onreadystatechange()
  32. httpRequest.open('GET', path);
  33. httpRequest.send();
  34. }
  35.  
  36.  
  37. // Redirect to post URL based on API results
  38. // API docs: https://developer.wordpress.com/docs/api/
  39. fetchJSONFile("https://public-api.wordpress.com/rest/v1.1/sites/"+blogid, function(data) {
  40. var postURL;
  41.  
  42. if(postid == "new") {
  43. postURL=data.URL+"/wp-admin/post-new.php?post_type="+postType;
  44. }//if
  45. else {
  46. postURL=data.URL+"/wp-admin/post.php?post="+postid+"&action=edit";
  47. }//end if
  48.  
  49. window.location.replace(postURL);
  50.  
  51. });