etFunctions: a library for Joe's EditorTools

A library to be used with Joe's EditorTools for Popmundo

目前為 2015-07-13 提交的版本,檢視 最新版本

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.cn-greasyfork.org/scripts/10938/61694/etFunctions%3A%20a%20library%20for%20Joe%27s%20EditorTools.js

  1. // ==UserScript==
  2. // @name etFunctions: a library for Joe's EditorTools
  3. // @namespace http://popmundo-diaries.com/
  4. // Author Joe Isaacs CharId #3248185 <joe.isaacs.pm@gmail.com>
  5. // @description A library to be used with Joe's EditorTools for Popmundo
  6. // @version 1.0
  7. // ==/UserScript==
  8.  
  9. // Translation labels object
  10. var _etChanged = false;
  11.  
  12. function etBeforeUnload(){
  13. if( _etChanged === false ) return true;
  14. return confirm( "You have unsaved content. Are you sure you want to leave?" );
  15. }
  16.  
  17. function etOnSubmit(){
  18. if( _etChanged === false ) return true;
  19. return confirm( "You have unsaved content. Are you sure you want to change the article state?" );
  20. }
  21.  
  22.  
  23. // Return tomorrow's date at 11:00 time
  24. function etGetDate(){
  25. var currentDate = new Date();
  26. currentDate = new Date( new Date().getTime() + 24 * 60 * 60 * 1000 );
  27. var year = currentDate.getFullYear();
  28. var month = (currentDate.getMonth() + 1) < 10 ? '0' + ( currentDate.getMonth() + 1 ) : ( currentDate.getMonth() + 1 );
  29. var day = currentDate.getDate() < 10 ? '0' + currentDate.getDate() : currentDate.getDate();
  30. var hour = '11';
  31. var minutes = '00';
  32. return year + '-' + month + '-' + day + ' ' + hour + ':' + minutes;
  33.  
  34. }
  35.  
  36. // Change the date text value if it's empty
  37. function etChangeDate( objectId ){
  38. var obj = document.getElementById( objectId );
  39. if( obj.value.length >= 1 ) return;
  40. obj.value = etGetDate();
  41. obj.setAttribute( "value", etGetDate() );
  42. }