User talk:Omegatron/monobook.js

Latest comment: 9 years ago by Technical 13 in topic Legacy JavaScript
Skillz
js-1This user is a beginning JavaScript programmer.
meatThis user is mostly or entirely made of meat.

To do edit

  • use nbsp between number and unit?
  • en dash between digits with a unit or percent after?
    • 4-5dB → 4–5 dB
  • add a word boundary after unit in regexps so words like... um... "5radians" don't get converted into "5 radians"?
    • and before numbers
  • periods aren't counted towards em dashes
  • add hz --> Hz
  • Make it stop converting "1970s" to "1970 s" -- \d?\d?\d0s
    • nevermind, skip plain s
  • fix things like "6,3 mm" → "6.3 mm", "1 000 m" → "1,000 m" as per MoS
  • Add unicode number entities to replacement lists:
  • Write something to fix heading format, as if it had been added with the + tab
    • (={2,})( |\t)*(.*?)( |\t)*(={2,})(\n)+ → $1 $3 $5$6$6
  • Write something to change "+/-" into ±
    • (\s|\d)\+\/(-|−|-)(\s|\d) → $1±$3
  • Fix external links and see also sections
  • Press preview by default after clicking tab
  • everything should ignore the insides of math tags
  • extra newline remover should count lines with only whitespace too
  • Rewrite units thing without depending on clunky regexps
  • "12-mm" → "12 mm"
  • lowercase units when written out?
  • These aren't working correctly:
  • link the first occurrence of each unit
  • Audio links script should replace "help" with "Audio help", "info" with "File info" or "File details"
  • some buttons for saving with specific edit summaries? Like "Formatting" "Spelling" etc for people like me who don't put edit summaries?
  • write your own shortened diff for the automatic edit summaries?!1? It could be done, probably. Have javascript save the original textarea to a variable, and when you press submit, it does a comparison of the current textarea and the original and adds a summary of the diff. i wish i knew js better.

SI regular expressions edit

Prefixes: Y Z E P T G M k h da d c m μ µ µ n p f a z y

  • ['Y', 'Z', 'E', 'P', 'T', 'G', 'M', 'k', 'h', 'da', 'd', 'c', 'm', 'µ', 'n', 'p', 'f', 'a', 'z', 'y']

Base units: g s m A K mol cd

  • ['g', 's', 'm', 'A', 'K', 'mol', 'cd']

Derived units: rad sr Hz N J W Pa lm lx C V Ω ohm Ω F Wb T H S Bq Gy Sv kat °C °C M

Accepted units: L

Other units to treat the same way: B dB

  1. Convert all occurrences (in the presence of numbers and prefixes):
    • ° → °
      • ° → °
    • Ω or ohm or Ohm → Ω
      • (\d)\s?(Y|Z|E|P|T|G|M|k|K|h|da|d|c|m|µ|μ|µ|n|p|f|a|z|y)?(Ω|ohm|Ohm)s? → $1 $2Ω
    • μ or μ or µ → µ
      • (\d)\s?(μ|μ|µ)(g|s|m|A|K|mol|cd|rad|sr|Hz|N|J|W|Pa|lm|lx|C|V|Ω|F|Wb|T|H|S|Bq|Gy|Sv|kat|°C|M) → $1 µ$3
    • K → k before units (will conflict with compound units that should be K⋅something)
      • (\d)\s?K(g|s|m|A|K|mol|cd|rad|sr|Hz|N|J|W|Pa|lm|lx|C|V|Ω|F|Wb|T|H|S|Bq|Gy|Sv|kat|°C|M) → $1 k$3
  2. spaces between numbers and units
    • (\d)\s?(dB|B)\b → $1 $3
    • (\d)\s?(Y|Z|E|P|T|G|M|k|K|h|da|d|c|m|µ|n|p|f|a|z|y)?(g|s|m|A|K|mol|cd|rad|sr|Hz|N|J|W|Pa|lm|lx|C|V|Ω|F|Wb|T|H|S|Bq|Gy|Sv|kat|°C|M) → $1 $2$3

Digital units

  1. Decimal
    • kbits/s or kb/s or kbps or Kbps → kbit/s
      • [KkMmGgTtPpEeYyZz](bps|bits?\/s|b\/s) → $1bit/s
    • kbytes/s or kbyte/s (or KB/s?) or kBps or KBps → kB/s
      • [KkMmGgTtPpEeYyZz](Bps|bytes?\/s|B\/s) → $1B/s
  2. Binary
    • Kib or kib → Kibit
      • [KkMmGgTtPpEeYyZz]ib → $1ibit
    • kiB → KiB
      • [KkMmGgTtPpEeYyZz]iB → $1iB
    • Common error
      • mibi(bit|byte) /i → mebi$1

kbit/s kB/s Kibit/s KiB/s

can the entire set of units be defined as a variable and included in regexps?

maybe match for the entire thing and say "these pieces are units", and then run each unit through separate rules that correct each part?

these don't handle capitalization yet. can you match on several things but only use some?

False positive on dates edit

Make it stop converting "1970s" to "1970 s"

Convert: 1000 s 1954 s

Don't convert: 1970s 70s 1800s 00s

-- \d?\d?\d0s

You know what? We're never going to see "1000 s". Just skip it.

Legacy JavaScript edit

Hello! This script has been detected as using deprecated parameters that need to be replaced with the updated version. Examples include addOnloadHook( ... ) needs to be replaced with $( ... ) or $( function() { ... } ) (depending on use); all wgGlobalVariables need to be properly gotten with mw.config.get( 'wgGlobalVariable' ); and addPortletLink needs to be called with mw.util.addPortletLink. Please see MW:ResourceLoader/Legacy JavaScript for details. Thank you. — {{U|Technical 13}} (etc) 21:53, 19 January 2015 (UTC)Reply