Advertisement
briank

this_year.js.html

Jan 12th, 2020 (edited)
661
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.15 KB | None | 0 0
  1. <script type='text/javascript'>
  2. // In a Kartra membership, remove the // on the next line to hide the code in preview and live
  3. // if (location.pathname.indexOf('/membership/edit')) document.currentScript.parentElement.parentElement.style.display = 'none';
  4. // Replace {FROM SEP this year} in <p>aragraphs using jQuery (e.g. for copyright notices)
  5. // FROM (starting year) and SEP (separator) are optional; "this year" is case-insensitive
  6. // In 2020: {this year} => 2020; {2018-this year} => 2018-2020; {2018 to This Year} => 2018 to 2020; {2020-THIS YEAR} => 2020
  7. // Placed in the public domain by author Brian Katzung <briank@kappacs.com>
  8. jQuery(function () {
  9.     var thisYear = new Date().getFullYear();
  10.     // You could use jQuery('p,div')... if necessary, but it will take longer
  11.     jQuery('p').each(function () {
  12.         this.innerHTML = this.innerHTML.replace(/{[^}]*this year}/ig, function (outer) {
  13.             var match = outer.match(/{(\d*)(.*)this year}/i);
  14.             if (match[1] && match[1] != thisYear) {
  15.                return '' + match[1] + match[2] + thisYear;
  16.             }
  17.             return thisYear;
  18.         });
  19.     });
  20. });
  21. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement